#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
struct Edge {
int from, to, cost, lid;
bool operator>(const Edge &e) const {
return cost > e.cost;
}
};
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, k;
while (cin >> n >> k) {
vector<vector<Edge>> g(100);
vector<int> speed(n + 1);
for (int i = 1; i <= n; ++i) cin >> speed[i];
cin.ignore();
for (int i = 1; i <= n; ++i) {
string s;
getline(cin, s);
stringstream ss(s);
vector<int> flrs;
int f;
while (ss >> f) flrs.push_back(f);
for (int x = 0; x < flrs.size(); ++x) {
for (int y = x + 1; y < flrs.size(); ++y) {
int a = flrs[x], b = flrs[y];
g[a].push_back({a, b, 0, i});
g[b].push_back({b, a, 0, i});
}
}
}
vector<int> dist(100, -1), last(100, -1);
priority_queue<Edge, vector<Edge>, greater<Edge>> pq;
pq.push({0, 0, 0, 0});
dist[0] = 0;
while (!pq.empty()) {
Edge cur = pq.top(); pq.pop();
if (dist[cur.to] != cur.cost) continue;
for (int i = 0; i < g[cur.to].size(); ++i) {
Edge e = g[cur.to][i];
int t = abs(e.to - e.from) * speed[e.lid];
if (last[e.from] != -1 && last[e.from] != e.lid) t += 60;
int newCost = dist[e.from] + t;
if (dist[e.to] == -1 || newCost < dist[e.to]) {
dist[e.to] = newCost;
last[e.to] = e.lid;
pq.push({e.from, e.to, newCost, e.lid});
}
}
}
if (dist[k] == -1) cout << "IMPOSSIBLE" << endl;
else cout << dist[k] << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgaW50IGxvbmcgbG9uZwojZGVmaW5lIGVuZGwgIlxuIgoKc3RydWN0IEVkZ2UgewogICAgaW50IGZyb20sIHRvLCBjb3N0LCBsaWQ7CiAgICBib29sIG9wZXJhdG9yPihjb25zdCBFZGdlICZlKSBjb25zdCB7CiAgICAgICAgcmV0dXJuIGNvc3QgPiBlLmNvc3Q7CiAgICB9Cn07CgpzaWduZWQgbWFpbigpewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsKICAgIGNpbi50aWUoMCk7IGNvdXQudGllKDApOwogICAgCiAgICBpbnQgbiwgazsKICAgIHdoaWxlIChjaW4gPj4gbiA+PiBrKSB7CiAgICAgICAgdmVjdG9yPHZlY3RvcjxFZGdlPj4gZygxMDApOwogICAgICAgIHZlY3RvcjxpbnQ+IHNwZWVkKG4gKyAxKTsKICAgICAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyArK2kpIGNpbiA+PiBzcGVlZFtpXTsKCiAgICAgICAgY2luLmlnbm9yZSgpOwogICAgICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47ICsraSkgewogICAgICAgICAgICBzdHJpbmcgczsKICAgICAgICAgICAgZ2V0bGluZShjaW4sIHMpOwogICAgICAgICAgICBzdHJpbmdzdHJlYW0gc3Mocyk7CiAgICAgICAgICAgIHZlY3RvcjxpbnQ+IGZscnM7CiAgICAgICAgICAgIGludCBmOwogICAgICAgICAgICB3aGlsZSAoc3MgPj4gZikgZmxycy5wdXNoX2JhY2soZik7CgogICAgICAgICAgICBmb3IgKGludCB4ID0gMDsgeCA8IGZscnMuc2l6ZSgpOyArK3gpIHsKICAgICAgICAgICAgICAgIGZvciAoaW50IHkgPSB4ICsgMTsgeSA8IGZscnMuc2l6ZSgpOyArK3kpIHsKICAgICAgICAgICAgICAgICAgICBpbnQgYSA9IGZscnNbeF0sIGIgPSBmbHJzW3ldOwogICAgICAgICAgICAgICAgICAgIGdbYV0ucHVzaF9iYWNrKHthLCBiLCAwLCBpfSk7CiAgICAgICAgICAgICAgICAgICAgZ1tiXS5wdXNoX2JhY2soe2IsIGEsIDAsIGl9KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgdmVjdG9yPGludD4gZGlzdCgxMDAsIC0xKSwgbGFzdCgxMDAsIC0xKTsKICAgICAgICBwcmlvcml0eV9xdWV1ZTxFZGdlLCB2ZWN0b3I8RWRnZT4sIGdyZWF0ZXI8RWRnZT4+IHBxOwogICAgICAgIHBxLnB1c2goezAsIDAsIDAsIDB9KTsKICAgICAgICBkaXN0WzBdID0gMDsKCiAgICAgICAgd2hpbGUgKCFwcS5lbXB0eSgpKSB7CiAgICAgICAgICAgIEVkZ2UgY3VyID0gcHEudG9wKCk7IHBxLnBvcCgpOwogICAgICAgICAgICBpZiAoZGlzdFtjdXIudG9dICE9IGN1ci5jb3N0KSBjb250aW51ZTsKCiAgICAgICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgZ1tjdXIudG9dLnNpemUoKTsgKytpKSB7CiAgICAgICAgICAgICAgICBFZGdlIGUgPSBnW2N1ci50b11baV07CiAgICAgICAgICAgICAgICBpbnQgdCA9IGFicyhlLnRvIC0gZS5mcm9tKSAqIHNwZWVkW2UubGlkXTsKICAgICAgICAgICAgICAgIGlmIChsYXN0W2UuZnJvbV0gIT0gLTEgJiYgbGFzdFtlLmZyb21dICE9IGUubGlkKSB0ICs9IDYwOwogICAgICAgICAgICAgICAgaW50IG5ld0Nvc3QgPSBkaXN0W2UuZnJvbV0gKyB0OwogICAgICAgICAgICAgICAgaWYgKGRpc3RbZS50b10gPT0gLTEgfHwgbmV3Q29zdCA8IGRpc3RbZS50b10pIHsKICAgICAgICAgICAgICAgICAgICBkaXN0W2UudG9dID0gbmV3Q29zdDsKICAgICAgICAgICAgICAgICAgICBsYXN0W2UudG9dID0gZS5saWQ7CiAgICAgICAgICAgICAgICAgICAgcHEucHVzaCh7ZS5mcm9tLCBlLnRvLCBuZXdDb3N0LCBlLmxpZH0pOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBpZiAoZGlzdFtrXSA9PSAtMSkgY291dCA8PCAiSU1QT1NTSUJMRSIgPDwgZW5kbDsKICAgICAgICBlbHNlIGNvdXQgPDwgZGlzdFtrXSA8PCBlbmRsOwogICAgfQogICAgcmV0dXJuIDA7Cn0K