#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,m;ll k,a[1000010],b[1000010],lcm,f[1000010];bool z[1000010];
ll gcd(ll x,ll y){if(x<y) swap(x,y);return !y?x:gcd(y,x%y);}
ll exgcd(ll a,ll b,ll &x,ll &y)
{
	if(!b)
	{
		x=1,y=0;
		return a;
	}
	ll gcd=exgcd(b,a%b,x,y);
	ll tmp=x;x=y;y=tmp-a/b*y;
	return gcd;
}
ll excrt(ll a,ll b,ll c,ll d)
{
	ll e=d-c,x,y;
	ll gcd=exgcd(a,b,x,y);
	if(e%gcd) return -1;
	x=e/gcd*x;b/=gcd;
	x=(x%b+b)%b;
	ll ans=x*a+c;ans=(ans%lcm+lcm)%lcm;
	if(!ans) ans=lcm;
	return ans;
}
void init()
{
	ll x,y;
	lcm=1ll*n/gcd(n,m)*m;
	for(int i=1;i<=max(n,m)*2;i++)
		if(a[i]&&b[i])
		{
			f[i]=excrt(n,m,a[i],b[i]);
			if(f[i]!=-1) z[i]=true;
		}
}
bool check(ll x)
{
	ll sum=0;
	for(int i=1;i<=max(n,m)*2;i++)
		if(z[i])
			sum+=x/lcm+(x%lcm>=f[i]);
	return x-sum>=k;
}
int main()
{
	scanf("%d %d %lld",&n,&m,&k);
	for(int i=1,x;i<=n;i++)
		scanf("%d",&x),a[x]=i;
	for(int i=1,x;i<=m;i++)
		scanf("%d",&x),b[x]=i;
	init();
	ll l=1,r=1e18,ans;
	while(l<=r)
	{
		ll mid=l+r>>1;
		if(check(mid))
			r=mid-1,ans=mid;
		else
			l=mid+1;
	}
	printf("%lld",ans);
}