#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <math.h>
#include <cstring>
#include <time.h>
#include <complex>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <set>
#include <bitset>

#pragma warning(disable:4996)
#define PII std::pair<long long, long long>
#define PTT std::pair<tree *, tree *>

template<typename T> T min(T x, T y)
{
	return x < y ? x : y;
}
template<typename T> T max(T x, T y)
{
	return x > y ? x : y;
};

const long long INF = 2000000005;//00000;// autojs.org
const long long mod = 1000000007;// 998244353;//
const long long MAXN = 5000005;

long long gcd(long long x, long long y)
{
	return !y ? x : gcd(y, x % y);
}
PII exgcd(long long x, long long y)
{
	if (!y)
		return { 1,0 };
	PII t = exgcd(y, x % y);
	return { t.second,t.first - (x / y) * t.second };
}

long long N, M, K, g, ng, mg, inv;
long long a[MAXN], b[MAXN];
long long pos[2 * MAXN];//x在b中出现的位置
std::vector<long long> num[MAXN];//ai前k轮多少次不同
long long st[MAXN];//i,j第一次相遇在第几轮

long long cal(long long d)//x轮有几次不同
{
	long long sum = 0;
	for (long long i = 0; i < N; i++)
	{
		long long t = st[i];
		if (t != -1 && d >= t*N + i)
			sum += 1 + (d - t*N - i) / (N * mg);
	}
	return d + 1 - sum;
}
void solve()
{
	long long l = -1, r = 2000000000000000000;
	while (r - l > 1)
	{
		long long mid = (l + r) / 2;
		if (cal(mid) >= K)
			r = mid;
		else
			l = mid;
	}
	printf("%lld\n", r + 1);
}

long long calcu(long long i, long long j)
{
	long long b = (j - i + M) % M;
	if (b % g) return -1;
	return ((b / g * inv) % mg + mg) % mg;
}

void init()
{
	for (long long i = 0; i < 2 * MAXN; i++)
		pos[i] = -1;
	scanf("%lld %lld %lld", &N, &M, &K);
	for (long long i = 0; i < N; i++)
		scanf("%lld", a + i);
	for (long long i = 0; i < M; i++)
		scanf("%lld", b + i), pos[b[i]] = i;

	g = gcd(N, M);//g != N && g != M
	ng = N / g, mg = M / g;// , ng %= mg;
	inv = exgcd(ng, mg).first;
	inv = (inv % mg + mg) % mg;

	for (long long i = 0; i < N; i++)
		if (pos[a[i]] != -1)
			st[i] = calcu(i, pos[a[i]]);
		else
			st[i] = -1;
}

int main()
{
	init();
	solve();

	return 0;
}