#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, data1[13][13], data2[13][13];
  cin >> n >> m;
  memset(data1, 0, sizeof(data1));
  memset(data2, 0, sizeof(data2));
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    data1[y][x] = data1[x][y] = 1;
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    data2[x][y] = data2[y][x] = 1;
  }
  int visit1[13][13], visit2[13][13], index;
  memset(visit1, 0, sizeof(visit1));
  memset(visit2, 0, sizeof(visit2));
  for (int i = 1; i < 13; i++) {
    for (int j = 1; j < 13; j++) {
      if (i == j) continue;
      for (int k = 1; k < 13; k++) {
        if (k == j) continue;
        if (data1[i][j] && data1[i][j] == data2[i][k]) {
          visit1[i][j]++;
          visit2[i][k]++;
          index = i;
        }
      }
    }
  }
  int count;
  count = 0;
  for (int i = 1; i < 13; i++) {
    for (int j = 1; j < 13; j++) {
      if (visit1[i][j]) {
        count++;
        break;
      }
    }
  }
  if (count == 1) {
    cout << index;
    return 0;
  }
  for (int i = 1; i < 13; i++) {
    for (int j = 1; j < 13; j++) {
      if (i == j) continue;
      if ((visit1[i][j] && visit1[j][i]) || (visit2[i][j] && visit2[j][i])) {
        cout << "-1";
        return 0;
      }
    }
  }
  cout << "0";
  return 0;
}
