#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



int n, m, c, a;

int memo[15000000];

int encode(vector<vint> state) {
    int res = 0;
    vint num(n, 0);
    for (int i = 0; i < state.size(); ++i) {
        for (int j = 0; j < state[i].size(); ++j) {
            int a = state[i][j];
            num[a] = i;
        }
    }
    for (int i = n-1; i >= 0; --i) {
        res += num[i];
        if (i != 0) res *= 3;
    }
//    COUT(state);
//    COUT(num);
//    COUT(res);
    return res;
}

vector<vint> decode(int num) {
    vector<vint> res(3);
    for (int i = 0; i < n; ++i) {
        int a = num % 3;
        res[a].PB(i);
        num /= 3;
    }
    return res;
}

int main() {
    while (cin >> n >> m) {
        if (n == 0) break;
        
        memset(memo, -1, sizeof(memo));
        vector<vint> start(3);
        for (int i = 0; i < 3; ++i) {
            vint tmp;
            cin >> a;
            for (int j = 0; j < a; ++j) { cin >> c; tmp.PB(c-1); }
            start[i] = tmp;
        }
        
        int es = encode(start);
        memo[es] = 0;
        queue<int> que;
        que.push(es);
        
//        COUT(start);
//        COUT(es);
//        COUT(decode(es));
        
        int res = m+1;
        while (!que.empty()) {
            int int_now = que.front(); que.pop();
            vector<vint> now = decode(int_now);
            
            //COUT(now); COUT(dist[now]);
            
            if (now[1].empty() && now[2].empty()) { chmin(res, memo[int_now]); break; }
            if (now[0].empty() && now[1].empty()) { chmin(res, memo[int_now]); break; }
            
            if (memo[int_now] == m) continue;
            
            // A to B
            if (!now[0].empty()) {
                bool ok = true;
                if (!now[1].empty()) if (now[0].back() <= now[1].back()) ok = false;
                if (ok) {
                    vector<vint> next = now;
                    next[1].push_back(now[0].back());
                    next[0].pop_back();
                    int en = encode(next);
                    if (memo[en] == -1) {
                        memo[en] = memo[int_now] + 1;
                        que.push(en);
                    }
                }
            }
            
            if (!now[1].empty()) {
                bool ok = true;
                if (!now[0].empty()) if (now[1].back() <= now[0].back()) ok = false;
                if (ok) {
                    vector<vint> next = now;
                    next[0].push_back(now[1].back());
                    next[1].pop_back();
                    int en = encode(next);
                    if (memo[en] == -1) {
                        memo[en] = memo[int_now] + 1;
                        que.push(en);
                    }
                }
            }
                
            if (!now[1].empty()) {
                bool ok = true;
                if (!now[2].empty()) if (now[1].back() <= now[2].back()) ok = false;
                if (ok) {
                    vector<vint> next = now;
                    next[2].push_back(now[1].back());
                    next[1].pop_back();
                    int en = encode(next);
                    if (memo[en] == -1) {
                        memo[en] = memo[int_now] + 1;
                        que.push(en);
                    }
                }
            }
            
            if (!now[2].empty()) {
                bool ok = true;
                if (!now[1].empty()) if (now[2].back() <= now[1].back()) ok = false;
                if (ok) {
                    vector<vint> next = now;
                    next[1].push_back(now[2].back());
                    next[2].pop_back();
                    int en = encode(next);
                    if (memo[en] == -1) {
                        memo[en] = memo[int_now] + 1;
                        que.push(en);
                    }
                }
            }
        }
        
        if (res <= m) cout << res << endl;
        else cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 59828