#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b); i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const char nl = '\n';
const ll MX = 2e12; //check the limits, dummy

unordered_map<int, int> c1, c2;
unordered_set<int> shared;
vector<ll> q;
// unordered_map<int, ll> newS;
ll n, m, k, g;
ll p;
template <typename T>
T gcd(T a, T b) {
	return a ? gcd(b % a, a) : b;
}
ll rev(ll x, ll m) {
	return x == 1 ? 1 : (1 - rev(m % x, x) * (ll)m) / x + m;
}
ll CRT(ll a1, ll m1, ll a2, ll m2) { return (a1 - a2 % m1 + m1) * (ll)rev(m2, m1) % m1 * m2 + a2; }
ll check(ll x) {
  return lower_bound(all(q),x)-q.begin();
}
void solve(int t) {
	int x;
	cin >> n >> m >> k;
	g = gcd(max(m, n), min(m, n));
	F0R(i, n) {
		cin >> x;
		c1[x] = i + 1;
	}
	F0R(i, m) {
		cin >> x;
		c2[x] = i + 1;
		if (c1.find(x) != c1.end()) {
			if (c2[x] % g == c1[x] % g) {
        // c1[x] mod n and i mod m
				q.pb(CRT(c1[x] / g, n / g, c2[x] / g, m / g) * g + (c1[x] % g));
			}
		}
	}
	sort(all(q));
	// lcm
	p = n * m / g;
	// number that anger him per lcm-cycle
	ll nw = p - q.size();
	ll h = (k - 1) / nw;
	ll ret = h * p;
	k -= h * (nw);
	ll l = 1, r = p;
	while (l < r) {
		ll m = l + (r - l) / 2;
    ll x = check(m+1);
		if (m - check(m + 1) >= k) {
			r = m;
		} else {
			l = m+1;
		}
	}
	cout << r + ret << nl;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int T = 1;
	F0R(i, T) {
		solve(i + 1);
	}
}

// read the question correctly (ll vs int)
// template by bqi343