#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

const pii Dir[8] = { //?????????
	{ 0,1 },{ 0,-1 },{ 1,0 },{ -1,0 },
	{ 1,1 },{ 1,-1 },{ -1,-1 },{ -1,1 }
};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}

signed main() {
	int n, m;
	ll dp[16] = {};
	dp[0] = 1;
	rep(i, 1,16) {
		dp[i] = dp[i - 1] * 3;
	}

	while (scanf("%d %d", &n, &m)) {
		if (n == 0)
			break;
		vector<int> pos(n);
		REP(i, 3) {
			int c;
			scanf("%d", &c);


			REP(j, c) {
				int size;
				scanf("%d", &size);

				pos[size - 1] = i;
			}
		}
		ll ans = 0, ans2 = 0;
		bool curs = 0;
		REP(i, n) {
			if (pos[i] % 2) {
				ans += dp[n - i - 1];
				curs = 1 - curs;
			}
			else if (curs * 2 - pos[i]) {
				ans += dp[n - i-1]*2;
			}
		}
		curs = 1;
		REP(i, n) {
			if (pos[i] % 2) {
				ans2 += dp[n - i - 1];
				curs = 1 - curs;
			}
			else if (curs * 2 - pos[i]) {
				ans2 += dp[n - i-1]*2;
			}
		}
		ans = min(ans2, ans);
		if (ans > m)
			ans = -1;
		printf("%lld\n", ans);
	}
	return 0;
}