#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define _ << " "
#define ins(a, n, x) (a).insert((a).begin(), (n), (x));
#define popcnt __builtin_popcount
#define popcntll __builtin_popcountll
#define __ << "\n"
#define vt vector

typedef long long int ll;
typedef double lf;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vl;

const int mod = 1e9 + 7;

inline int add(int a, int b) {a += b; if(a >= mod) a-= mod; if(a < 0) a += mod; return a;}
inline int mult(int a, int b) {return (long long) a * b % mod;}
inline int pot(int a, int b) {int ret = 1; while(b){if(b & 1) ret = mult(ret, a); a = mult(a, a); b >>= 1;} return ret;}
inline int divide(int a, int b) {return mult(a, pot(b, mod - 2));}
inline ll raand() {return (ll)rand() * RAND_MAX + rand();}
inline ll raaand() {return raand() * (mod - 7) + raand();}

ll gcd(ll a, ll b) {
	if(!b) return a;
	return gcd(b, a % b);
}

int main()
{
	srand(time(NULL));
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n, m, k, a;
	cin >> n >> m >> k;
	vt<pll> pairs(2 * max(n, m) + 10, make_pair(-1, -1));
	REP(i, n) {
		cin >> a;
		pairs[a].first = i;
	}
	REP(i, m) {
		cin >> a;
		pairs[a].second = i;
	}
	ll nm = n * m / gcd(n, m);
	ll offset = max(n, m) + 10;
	vl dis(2 * offset, -1);
	ll pn = 0, pm = 0, cnt = 0, cur;
	do {
		dis[pn - pm + offset] = cnt;
		cur = min(n - pn, m - pm);
		cnt += cur;
		pn += cur;
		pm += cur;
		if(pn >= n) pn -= n;
		if(pm >= m) pm -= m;
	} while(pn || pm);
	vl fo;
	REP(i, 2 * max(n, m) + 10) {
		if(pairs[i].first == -1 || pairs[i].second == -1 || dis[pairs[i].first - pairs[i].second + offset] == -1) continue;
		fo.pb(dis[pairs[i].first - pairs[i].second + offset] + min(pairs[i].first, pairs[i].second));
	}
	ll lo = 0, hi = 1e18, mid;
	while(lo < hi) {
		mid = (lo + hi) / 2;
		ll tot = mid + 1;
		for(ll x : fo) tot -= (mid + nm - x) / nm;
		if(tot < k) lo = mid + 1;
		else hi = mid;
	}
	cout << lo + 1 << endl;
	return 0;
}
