#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
int main() {
	int ans1, ans2;
	int n, m, na, nb, nc, tyo, place[16], ans;
	int cup[3][16];
	while (1) {
		for (int i = 0; i < 3; ++i) {
			for (int j = 0; j < 16; ++j)
				cup[i][j] = 0;
		}
		cin >> n >> m;
		if (n == 0 && m == 0) break;
		cin >> na;
		for (int i = 0; i < na; ++i) cin >> cup[0][i];
		cin >> nb;
		for (int i = 0; i < nb; ++i)cin >> cup[1][i];
		cin >> nc;
		for (int i = 0; i < nc; ++i)cin >> cup[2][i];
		for (int p = 0; p < 2; ++p) {
			tyo = 0;
			if (p == 0)place[0] = 0;
			else place[0] = 2;
			int np;
			if (place[0] == 0)np = 2;
			else np = 0;
			for (int k = 1; k < 16; ++k) place[k] = place[0];
			bool bo = false; int at, ar;
			for (int i = 1; i <= n; ++i) {
				for (int j = 0; j < na; ++j) {
					if (cup[0][j] == i) {
						at = 0;
						ar = j;
						bo = true;
						break;
					}
				}
				for (int j = 0; j < nb; ++j) {
					if (bo)break;
					if (cup[1][j] == i) {
						at = 1;
						ar = j;
						bo = true;
						break;
					}
				}
				for (int j = 0; j < nc; ++j) {
					if (bo)break;
					if (cup[2][j] == i) {
						at = 2;
						ar = j;
						bo = true;
						break;
					}
				}
				bo = false;
				if (at == place[i]) {
				}
				else {
					if (at == 1) {
						tyo += pow(3, n - i);
						for (int k = i + 1; k < 16; ++k) {
							if (place[k] == 0)place[k] = 2;
							else place[k] = 0;
						}
					}
					else tyo += 2 * (pow(3, n - i));
				}
			}
			if (p == 0)ans1 = tyo;
			else ans2 = tyo;
		}
		if (m < min(ans1, ans2))cout << -1 << endl;
		else cout << min(ans1, ans2) << endl;
	}
	return 0;
}
