#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(i, n) a[idx][i] = v[i]; idx++; PER = a;} while(next_permutation(ALL(v)));} while(0); // int fact(), VVI PERを宣言しておく
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
using VD = vector<double>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b; return true;} return false;}

void END(){cout << 1 << endl; exit(0);}

int n, m;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(true)
  {
    cin >> n >> m;
    if(n == 0 && m == 0) return 0;
    vector<stack<int>> goal(3), tray1(3), tray2(3);
    int ct = 0;
    REP(i, 3)
    {
      int c;
      cin >> c;
      REP(j, c)
      {
        ct++;
        tray1[0].push(ct);
        tray2[2].push(ct);
        int a;
        cin >> a;
        goal[i].push(a);
      }
    }
    int ans = INF;
    PII log = {-1, -1};
    REP(i, m)
    {
      REP(j, 3)
      {
        if (tray1[j].empty()) continue;
        bool flg = false;
        int now = tray1[j].top();
        for(int k = -1; k < 2; k += 2)
        {
          if (0 <= j+k && j+k < 3)
          {
            int before = log.first, cup = log.second;
            if (cup == now && before == j+k) continue;
            if (tray1[j+k].empty())
            {
              tray1[j+k].push(now);
              tray1[j].pop();
              flg = true;
              log = {j, now};
              break;
            }
            int next = tray1[j+k].top();
            if (now > next)
            {
              tray1[j+k].push(now);
              tray1[j].pop();
              flg = true;
              log = {j, now};
              break;
            }
          }
        }
        if (flg) break;
      }
      if (tray1 == goal)
      {
        chmin(ans, i+1);
        break;
      }
    }
    log = {-1, -1};
    REP(i, m)
    {
      REP(j, 3)
      {
        if (tray2[j].empty()) continue;
        bool flg = false;
        int now = tray2[j].top();
        for(int k = -1; k < 2; k += 2)
        {
          if (0 <= j+k && j+k < 3)
          {
            int before = log.first, cup = log.second;
            if (cup == now && before == j+k) continue;
            if (tray2[j+k].empty())
            {
              tray2[j+k].push(now);
              tray2[j].pop();
              flg = true;
              log = {j, now};
              break;
            }
            int next = tray2[j+k].top();
            if (now > next)
            {
              tray2[j+k].push(now);
              tray2[j].pop();
              flg = true;
              log = {j, now};
              break;
            }
          }
        }
        if (flg) break;
      }
      if (tray2 == goal)
      {
        chmin(ans, i+1);
        break;
      }
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3120