public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		Dijkstra G = new Dijkstra(101);
		while ((line = in.readLine()) != null && line.length() != 0) {
			int[] nk = readInts(line);
			int[] cost = readInts(in.readLine());
			G.init(101);
			for (int i = 0; i < cost.length; i++)
				G.cost[i] = cost[i];
			int[][] s = new int[nk[0]][];
			boolean[][] ss = new boolean[nk[0]][101];
			for (int i = 0; i < nk[0]; i++) {
				s[i] = readInts(in.readLine());
				for (int a = 0; a < s[i].length; a++) {
					ss[i][s[i][a]] = true;
					for (int b = a + 1; b < s[i].length; b++)
						G.union(s[i][a], s[i][b],
								cost[i] * Math.abs(s[i][b] - s[i][a]), i, true);
				}
			}
			if (G.dijkstra(0, nk[1]) == G.INF)
				out.append("IMPOSSIBLE\n");
			else
				out.append(G.dis[nk[1]] + "\n");
		}
		System.out.print(out);
	}