func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<int, int> > a_sent;   vector<pair<int, int> > b_sent;   set<pair<int, int> > a_possible;   set<pair<int, int> > b_possible;   int vis[10];   bool certain(pair<int, int> a, vector<pair<int, int> > sent) {     bool can_x = false;     bool can_y = false;     for (pair<int, int> b : sent) {       if (0) {         printf( has: [%d, %d], try: [%d, %d] n , a.first, a.second, b.first,                b.second);       }       if (a.first == b.first && a.second == b.second) continue;       if (a.first == b.second && a.second == b.first) continue;       if (a.first != b.first && a.second != b.second && a.first != b.second &&           a.second != b.first)         continue;       if (a.first == b.first || a.first == b.second) can_x = true;       if (a.second == b.first || a.second == b.second) can_y = true;     }     if (0) printf( can_x: %d, can_y: %d n , can_x, can_y);     return (can_x && !can_y) || (can_y && !can_x);   }   int main() {     cin >> n >> m;     while (n--) {       pair<int, int> pair;       cin >> pair.first >> pair.second;       if (pair.first < pair.second) swap(pair.first, pair.second);       a_sent.push_back(pair);     }     while (m--) {       pair<int, int> pair;       cin >> pair.first >> pair.second;       if (pair.first < pair.second) swap(pair.first, pair.second);       b_sent.push_back(pair);     }     for (pair<int, int> a : a_sent) {       for (pair<int, int> b : b_sent) {         if (a.first == b.first && a.second == b.second) continue;         if (a.first == b.second && a.second == b.first) continue;         if (a.first != b.first && a.second != b.second && a.first != b.second &&             a.second != b.first)           continue;         if (a.first == b.first) vis[a.first]++;         if (a.second == b.second) vis[a.second]++;         if (a.first == b.second) vis[a.first]++;         if (a.second == b.first) vis[a.second]++;         a_possible.insert(a);         b_possible.insert(b);       }     }     int cnt = 0;     for (int i = 1; i <= 9; ++i) {       cnt += vis[i] >= 1;       if (0) printf( vis[%d] = %d n , i, vis[i]);     }     if (0) cout << cnt << endl;     if (cnt == 1) {       for (int i = 1; i <= 9; ++i) {         if (vis[i] >= 1) {           cout << i << endl;           return 0;         }       }     }     for (pair<int, int> a : a_possible) {       if (!certain(a, b_sent)) {         cout << -1 << endl;         return 0;       }     }     for (pair<int, int> b : b_possible) {       if (!certain(b, a_sent)) {         cout << -1 << endl;         return 0;       }     }     cout << 0 << endl;   }   