#include <bits/stdc++.h>
#define N 500005
#define mod 998244353
//#define int long long

using namespace std;

typedef long long ll;

inline ll read()
{
	ll X=0; bool flag=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
	while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
	if(flag) return X;
	return ~(X-1);
}

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcm(int a, int b) {
	return ll(a) / ll(gcd(a, b)) * ll(b);
}
 
int exgcd(int a, int b, ll &x, ll &y) {
	if (b == 0) {
		x = 1; y = 0;
		return a;
	}
	int d = exgcd(b, a % b, x, y);
	ll tmp = x;
	x = y;
	y = tmp - a / b * y;
	return d;
}

ll n, m, k;
int a[N], b[N], t[N*5];
ll lcm_, gcd_, cur[N], tot = 0;

ll moved(int r, int c) {
	ll x = 0, y = 0;
	if (r == c) return r;
	if (r - c >= 0) {
		exgcd(m, n, x, y);
		if ((r - c) % gcd_ == 0) {
			int z = n / gcd_;
			x *= (r - c) / gcd_;
			return ll(c) + ll(m) * ((x % z + z) % z);
		}
	}
	else {
		exgcd(n, m, x, y);
		if ((c - r) % gcd_ == 0) {
			int z = m / gcd_;
			x *= (c - r) / gcd_;
			return ll(r) + ll(n) * ((x % z + z) % z);
		}
	}
	return -1;
}

void Init() {
	for (int i = 1; i <= n; i++) {
		if (t[a[i]]) {
			cur[++tot] = moved(i, t[a[i]]);
		}
	}
}

bool check(ll pos) {
	ll res = 0;
	for (int i = 1; i <= tot; i++) {
		if (cur[i] != -1) {
			if (cur[i] <= pos) res++;
			if (pos >= cur[i]) res += (pos - cur[i]) / lcm_;
		}
	}
	if (pos - res >= k) return true;
	else return false;
}

signed main(void) {
	scanf("%lld%lld%lld", &n, &m, &k);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1; i <= m; i++) scanf("%d", &b[i]), t[b[i]] = i;
	gcd_ = gcd(n, m);
	lcm_ = n / gcd_ * m;
	Init();
	ll l = 1, r = 1e18, ans = -1, st = 0;
	while (l <= r) {
		st++;
		ll mid = (l + r) / 2;
		if (check(mid)) r = mid - 1, ans = mid;
		else l = mid + 1;
	}
	cout << ans << '\n';
	return 0;
}