#include <bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define F first
#define S second
#define pb push_back
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define pii pair<int,int>
#define ppi pair<pii,int>
#define vi vector<int>
#define mp make_pair
#define minheap priority_queue<int,vector<int>,greater<int>>

int32_t main(){
FAST
 	int n,m,k;
 	cin>>n>>m>>k;
 	vi v1(n),v2(m),v3(n);
 	unordered_map<int,int> idx;
 	for(int i=0;i<n;i++) {
 		cin >> v1[i];
 		idx[v1[i]] = i;
 	}
 	for(int i=0;i<m;i++) {
 		cin >> v2[i];
 		if(idx.find(v2[i]) != idx.end()) {
 			v3[((idx[v2[i]]-i)%n+n)%n]++;
 		}
 	}

 	vi total = {0},idd = total;
 	int id = 0;

 	for(int i=1;i<=n;i++) {
 		total.pb(total.back()+v3[id]);
 		id = (id+m)%n;
 		idd.pb(id);
 	}

 	// for(int i=0;i<=n;i++) {
 	// 	cout << total[i] << '\n';
 	// }
 	int l = 1,r = 1e18;

 	while(l <= r) {
 		int x = (l+r)/2;
 		int mid = x;
 		// how many times same color in x days
 		int same = (x/(n*m)) * total[n];
 		
 		x %= n*m;

 		same += total[x/m];

 		int id = idd[x/m];
 		x %= m;
 		//if(x>=m) id = idd[x/m-1];
 		for(int i=id,j=0;j<x;i++,j++) {
 			if(v1[i%n] == v2[j%m]) same++;
 		}
 		

 		if(mid - same >= k) {
 			r = mid-1;
 		}
 		else {
 			l = mid+1;
 		}

 	}

 	cout<<l;

}