#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef pair P; #define rep(i, n) for (int i=0; i<(n); i++) #define all(c) (c).begin(), (c).end() #define uniq(c) c.erase(unique(all(c)), (c).end()) #define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin()) #define _1 first #define _2 second #define pb push_back #define INF 1145141919 #define MOD 1000000007 int N, M, Q; int U[100000], R[100000], T[100000]; int find(int x) { if (U[x] == x) return x; return find(U[x]); } void unite(int x, int y, int t) { x = find(x), y = find(y); if (x == y) return; if (R[x] > R[y]) swap(x, y); U[x] = y; T[x] = min(T[x], t); if (R[x] == R[y]) R[y]++; } int find(int x, int t) { if (T[x] > t) return x; return find(U[x], t); } signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> M >> Q; map mp; rep(i, M) { int a, b; cin >> a >> b; a--, b--; mp[P(a, b)] = 0; } rep(i, Q) { int a, b; cin >> a >> b; a--, b--; if (mp.find(P(a, b)) == mp.end()) swap(a, b); mp[P(a, b)] = Q-i; } rep(i, N) U[i] = i, R[i] = 1, T[i] = INF; vector > pp; for (auto p : mp) pp.pb(make_pair(p._2, P(p._1._1, p._1._2))); sort(all(pp)); for (auto p : pp) unite(p._2._1, p._2._2, p._1); for (int i=1; i 1) { int mid = (lo + hi) / 2; if (find(0, mid) == find(i, mid)) hi = mid; else lo = mid; } if (hi == 0) cout << -1 << "\n"; else cout << Q+1-hi << "\n"; } return 0; }