#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <utility>
#include <random>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <tuple>

//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,mmx,popcnt,tune=native")

using namespace std;

#define int long long
//const int INF = 1e9 + 30;
//const int MAXN = 1e5 + 228;
//const int MOD = 1e9 + 7;

int gcd (int a, int b, int & x, int & y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	int x1, y1;
	int d = gcd (b%a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return d;
}

bool find_any_solution (int a, int b, int c, int & x0, int & y0, int & g) {
	g = gcd (abs(a), abs(b), x0, y0);
	if (c % g != 0)
		return false;
	x0 *= c / g;
	y0 *= c / g;
	if (a < 0)   x0 *= -1;
	if (b < 0)   y0 *= -1;
	return true;
}
vector<int> s;
int stepAll;

int getAns(int d) {
    int ans = d + 1;
    for (int c: s) {
        ans -= d / stepAll;
        if (d % stepAll >= c) --ans;
    }
    return ans;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n);
    vector<int> p(2 * max(n, m) + 228, -1);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        --a[i];
        p[a[i]] = i;
    }
    vector<int> b(m);
    for (int i = 0; i < m; ++i) {
        cin >> b[i];
        --b[i];
    }
    int t1, t2;
    int g = gcd(n, m, t1, t2);
    int step = m / g;
    int step2 = n / g;
    stepAll = n * m / g;
    for (int i = 0; i < m; ++i) {
        if (p[b[i]] == -1) continue;
        int x0, y0;
        if (find_any_solution(n, -m, i - p[b[i]], x0, y0, t1)) {
            x0 = ((x0 % step) + step) % step;
            y0 = ((y0 % step2) + step2) % step2;
            assert(x0 * n + p[b[i]] == y0 * m + i);
            s.push_back((x0 * n + p[b[i]]) % stepAll);
        }
    }
    //cout << "!" << getAns(0) << " " << getAns(1) << " " << getAns(2) << " " << getAns(3) << "\n";
    int l = -1;
    int r = 1e18;
    while (r - l > 1) {
        int m = (r - l) / 2 + l;
        if (getAns(m) < k) {
            l = m;
        } else {
            r = m;
        }
    }
    cout << r + 1;
    return 0;
}
