// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>
#include <sstream>
#include <unistd.h>

#define ll long long
#define Int int
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define rep(n) for(int __x = 0; __x < n; __x++)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (x.at(x.size()-1))

using namespace std;

#define EPS 0.0000000001
#define MOD 1000000007

class Vector2 {
public:
  double x, y;
  
  Vector2(double x = 0, double y = 0): x(x), y(y) {}
  
  Vector2 operator + (Vector2 v) { return Vector2(x + v.x, y + v.y); }
  Vector2 operator - (Vector2 v) { return Vector2(x - v.x, y - v.y); }
  Vector2 operator * (double k) { return Vector2(x * k, y * k); }
  Vector2 operator / (double k) { return Vector2(x / k, y / k); }
  
  double length() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  double dot (Vector2 v) { return x * v.x + y * v.y; }
  double cross (Vector2 v) { return x * v.y - y * v.x; }
  
  bool operator < (const Vector2 &v) const {
    return x != v.x ? x < v.x : y < v.y;
  }
  
  bool operator == (const Vector2 &v) const {
    return fabs(x - v.x) < EPS && fabs(y - v.y) < EPS;
  }
};

ostream & operator << (ostream & out, Vector2 const & v) { 
  out<< "Vector2(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Vector2 & v) { 
  double x, y;
  in >> x;
  in >> y;
  v.x = x;
  v.y = y;
  return in;
}

#define MAX_N 15
#define MAX_M 15000000
#define INFTY (MAX_M+1)

Int N, M;

struct State {
  vector<vector<Int> > cups;
  Int ops;
  Vector2 lastMove;

  State(): cups(3), ops(0), lastMove(-1, -1) {}

  vector<Vector2> possibleMoves() {
    vector<Vector2> ret;
    vector<Int> indexes({ 0, 1, 2 });
    do {
      Int from = indexes.at(0), to = indexes.at(1);
      if (from == lastMove.y && to == lastMove.x) continue;
      if (abs(from - to) == 2) continue;
      if (!cups.at(from).size()) continue;
      if (cups.at(to).size() == 0) ret.push_back(Vector2(from, to));
      else if (last(cups.at(from)) > last(cups.at(to))) ret.push_back(Vector2(from, to));
    } while (next_permutation(span_all(indexes)));
    return ret;
  }

  State move(Vector2 &m) {
    State copy = *this;
    Int from = m.x, to = m.y;
    copy.cups.at(to).push_back(last(copy.cups.at(from)));
    copy.cups.at(from).pop_back();
    copy.lastMove = m;
    copy.ops++;
    return copy;
  }
};

ostream & operator << (ostream & out, State const & s) { 
  out << "A: ";
  for (auto x: s.cups.at(0)) out << x << "\t";
  out << endl;
  out << "B: ";
  for (auto x: s.cups.at(1)) out << x << "\t";
  out << endl;
  out << "C: ";
  for (auto x: s.cups.at(2)) out << x << "\t";
  out << endl;
  return out;
}

State state;

void input() {
  state.ops = 0;
  loop(i,0,3) state.cups.at(i).clear();
  state.lastMove = Vector2(-1, -1);
  cin >> N >> M;
  if (N == 0 && M == 0) exit(0);
  Int x, n;
  loop(i,0,3) {
    cin >> n;
    rep(n) {
      cin >> x;
      state.cups.at(i).push_back(x);
    }
  }
}

Int bfs() {
  if (state.cups.at(1).size() == 0) {
    if (state.cups.at(0).size() == 0 || state.cups.at(2).size() == 0) return 0;
  }
  queue<State> Q;
  Q.push(state);
  while (Q.size()) {
    State u = Q.front(); Q.pop();
    // cout << u << endl;
    for (auto mv: u.possibleMoves()) {
      State next = u.move(mv);
      if (next.cups.at(1).size() == 0) {
        if (next.cups.at(0).size() == 0 || next.cups.at(2).size() == 0) return next.ops;
      }
      if (next.ops < M) Q.push(next);
    }
  }
  return -1;
}

void solve() {
  cout << bfs() << endl;
}

int main(void) {
  while (1) {
    input();
    solve();
  }
  return 0;
}



Measured memory_bytes: 3096