#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
const int M = 20, N = 1 << M;
int n, m, k;
int a[100];
short dis[N];
int main() {
cin >> n >> m >> k;
for (int i = 0; i < n; i++)
for (int i = 0; i < k; i++) {
int t;
cin >> t;
a[i] |= 1 << (t - 1);
}
memset(dis, -1, sizeof(dis));
dis[0] = 0;
queue<int> q;
q.push(0);
while (!q.empty()) {
int u = q.front();
q.pop();
for (int i = 0; i < n; i++) {
int v = u | a[i];
if (dis[v] == -1) {
q.push(v);
dis[v] = dis[u] + 1;
}
}
}
cout << dis[(1 << m) - 1];
return 0;
}