#include <bits/stdc++.h>

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

vector<long long> V;
int A[500000], B[500000], P[1000000];

int GCD(int a, int b)
{
	for(;b;a%=b,swap(a,b));
	return a;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int N, M, G, X, XX=1, Y, YY=1;
	long long K, s=1, e=1e18, L;
	cin>>N>>M>>K; G=GCD(N,M); X=N/G; Y=M/G;
	L=1LL*N*M/G;
	for(int i=1;i<=500000;i++) {
		if(i<X && (1LL*Y*i)%X==1) YY=i;
		if(i<Y && (1LL*X*i)%Y==1) XX=i;
	}
	memset(P,-1,sizeof(P));
	for(int i=0;i<N;i++) cin>>A[i], P[--A[i]]=i;
	for(int i=0;i<M;i++) {
		cin>>B[i];
		B[i]--;
	}
	if(L==N) {
		for(int i=0;i<N;i++) if(A[i]==B[i%M]) V.push_back(i);
	}
	else if(L==M) {
		for(int i=0;i<M;i++) if(A[i%N]==B[i]) V.push_back(i);
	}
	else {
		for(int i=0;i<M;i++) if(P[B[i]]>-1 && i%G==P[B[i]]%G) V.push_back((1LL*(i/G)*X*XX+1LL*(P[B[i]]/G)*Y*YY)%(1LL*X*Y)*G+i%G);
	}
	for(auto v: V) assert(A[v%N]==B[v%M]);
	while(s<=e) {
		long long m=(s+e)>>1, S=m;
		for(auto v: V) S-=max(m-v+L-1,0LL)/L;
		if(S<K) s=m+1;
		else e=m-1;
	}
	cout<<s<<'\n';
	return 0;
}
