#include<bits/stdc++.h>
#define int long long
#define N 1000001
using namespace std;
int n,m,K,a[N+1],b[N+1],fl[N+1],ag,p[N+1],pn,g[N+1],ans;
int gcd(int x,int y){return (y%x==0)?x:gcd(y%x,x);}
int lcm(int x,int y){return x/gcd(x,y)*y;}
signed main(){
//	freopen("1.in","r",stdin);
//	freopen("a.out","w",stdout);
	cin>>n>>m>>K;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=m;i++)cin>>b[i];
//	for(int i=1,nt=0,n1=1,n2=1;nt<K;i++,n1=n1%n+1,n2=n2%m+1){
//		if(a[n1]!=b[n2])nt++;
//		if(nt==K)cout<<i<<endl;
//	}
//	if(n<m){
//		swap(n,m);
//		for(int i=1;i<=max(n,m);i++)swap(a[i],b[i]);
//	}
	for(int i=1;i<=n;i++)fl[a[i]]=i;
	int ng=gcd(n,m),nl=lcm(n,m),ni=0;
	for(int i=1;i<=n;i++){
		if(!g[i]){
			int nj=i;
			while(!g[nj]){
				g[nj]=++ni;
				nj=(nj+m-1)%n+1;
			}
		}
	}
	for(int i=1;i<=m;i++){
		if(fl[b[i]]){
			if(i%ng!=fl[b[i]]%ng)continue;
			ag++;
			p[++pn]=(g[(fl[b[i]]-i+m*n)%n+1]-1)*m+i;
		}
	}
	ans+=(K/(nl-ag)-1)*nl;
	K-=(nl-ag)*(K/(nl-ag)-1);int na=0,npn=pn;
	sort(p+1,p+pn+1);for(int i=1;i<=npn;i++)p[++pn]=nl+p[i];
	for(int i=1;i<=pn;i++){
		if(p[i]-p[i-1]-1+na>=K){
			ans+=(K-na);
			cout<<ans<<endl;
			return 0;
		}
		ans+=p[i]-p[i-1],na+=p[i]-p[i-1]-1;
	}
	cout<<ans+K-na<<endl;
	return 0;
}
/*
8 3 10
1 3 4 5 6 2 7 8
1 2 3
*/