#include <iostream>
#include <stack>
#include <string>
#include <sstream>
using namespace std;

class Cups {
public:
    Cups(int, int);
    void setInputData();
    void move();
    bool isGoal();
    bool canMove(char, char);
    int getStep();
private:
    stack<int> sA, sB, sC;  // startA, B, C
    stack<int> gA, gB, gC;  // goalA, B, C
    int n, m;
    int step;
    string prev;
};

Cups::Cups(int n, int m) {
    this->step = 0;
    this->n = n;
    this->m = m;
    // Default cups
    for (int i=1; i<=n; ++i) {
        sA.push(i);
    }
}
int Cups::getStep() {
    return step;
}
void Cups::setInputData() {
    int n, cup;
    cin >> n;
    for (int i=0; i<n; ++i) {
        cin >> cup; 
        gA.push(cup);
    }
    cin >> n;
    for (int i=0; i<n; ++i) {
        cin >> cup; 
        gB.push(cup);
    }
    cin >> n;
    for (int i=0; i<n; ++i) {
        cin >> cup; 
        gC.push(cup);
    }
}
bool Cups::isGoal() {
    if ((sA == gA && sB == gB && sC == gC) ||
        (sA == gC && sB == gB && sC == gA)) {
        return true;
    }
    return false;
}
void Cups::move() {
    if (canMove('A','B')) {
        sB.push(sA.top()); sA.pop();
        prev = "AtoB";
    } else if (canMove('C', 'B')) {
        sB.push(sC.top()); sC.pop();
        prev = "CtoB";
    } else if (canMove('B', 'A')) {
        sA.push(sB.top()); sB.pop();
        prev = "BtoA";
    } else if (canMove('B', 'C')) {
        sC.push(sB.top()); sB.pop();
        prev = "BtoC";
    }
    step ++;
}
bool Cups::canMove(char from, char to) {
    stringstream way;
    way << to << "to" << from;
    if (prev == way.str()) {
        return false;
    }

    int cup[3];
    cup[0] = sA.empty() ? 0 : sA.top();
    cup[1] = sB.empty() ? 0 : sB.top();
    cup[2] = sC.empty() ? 0 : sC.top();

    if (cup[from-'A'] > cup[to-'A']) {
        return true;
    }
    return false;
}

int main() {
    int n, m;
    while (cin >> n >> m && n!=0 && m!=0) {
        Cups cups(n, m);
        cups.setInputData();

        int res = -1;
        if (cups.isGoal()) {
            res = 0;
        } else {
            for (int i=0; i<m; i++) {
                cups.move();
                if (cups.isGoal()) {
                    res = cups.getStep();
                    break;
                }
            }
        }
        cout << res << endl;
    }
    return 0;
}