#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;++i)
#define per(i,a,n) for (int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define mem(a,b) memset(a,b,sizeof (a))
#define ios std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
// ios  can not be used with scanf,printf.  IF  ios MUST cin,cout.
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
const ll mod=1000000007;
const int INF=0x3f3f3f3f;
ll ksm(ll a,ll b){ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

const int N=5e5+10,M=N*2;
int n,m;
ll k;
int a[N],b[N];
ll A[N],B[N];
int pos[M];
vector<ll>v;
ll mul(ll a,ll b,ll p){
    ll res=0;
    while(b){
        if(b&1)res=(res+a)%p;
        a=(a+a)%p;
        b>>=1;
    }
    return res;
}
ll exgcd(ll a,ll b,ll &x,ll &y){
    if(!b){
        x=1,y=0;
        return a;
    }
    ll d=exgcd(b,a%b,y,x);
    y-=a/b*x;
    return d;
}
ll excrt(int n,ll m[],ll a[]){
    ll M=m[1],ans=a[1],x,y,d;
    for(int i=2;i<=n;i++){
        ll c=(a[i]-ans%m[i]+m[i])%m[i];
        d=exgcd(M,m[i],x,y);
        if(c%d)return -1;
        x=c/d*x%m[i];
        ans+=M*x;
        M=M/d*m[i];
        ans%=M;
    }
    return (ans%M+M)%M;
}
ll check(ll mid){
    return mid-(upper_bound(all(v),mid)-v.begin());
}
int main(){
    memset(pos,-1,sizeof pos);
    scanf("%d%d%lld",&n,&m,&k);
    for(int i=0;i<n;i++)scanf("%d",&a[i]),pos[a[i]]=i;
    for(int i=0;i<m;i++){
        scanf("%d",&b[i]);
        if(~pos[b[i]]){
            int j=pos[b[i]];
            A[1]=n,A[2]=m;
            B[1]=j,B[2]=i;
            ll x=excrt(2,A,B);
            if(x==-1)continue;
            v.pb(x+1);
        }
    }
    sort(all(v));
    ll times=lcm(n,m)-SZ(v);
    ll turns=(k-1)/times;
    k-=turns*times;
    ll ans=turns*lcm(n,m);
    ll l=0,r=lcm(n,m);
    while(l<r){
        ll mid=l+r>>1;
        if(check(mid)>=k)r=mid;
        else l=mid+1;
    }
    ans+=r;
    printf("%lld\n",ans);
    return 0;
}