#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define ll long long
#define maxn 500005

typedef pair<int, int> P;
ll n, m;
ll K;
ll A[maxn * 2], B[maxn * 2];
ll g;
ll st[maxn * 2];
vector<int> v;

ll exgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    ll r = exgcd(b, a % b, x, y);
    ll t = x;
    x = y;
    y = t - a / b * y;
    return r;
}

ll C(ll mid)
{
    ll sum = 0;
    for (int i : v)
    {
        // A[i]+nx=B[i]+my <= mid, nx-my=B-A
        sum += ((mid - A[i] - (ll)n * st[i]) + (ll)n * m / g) / ((ll)n * m / g);
    }
    //printf("%lld\n", sum);
    return mid + 1 - sum;
}

int main()
{
    //freopen("4-16.in", "r", stdin);
    //freopen("a218_09.out", "w", stdout);
    //std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> m >> K;
    for (int i = 1; i <= n; i++)
    {
        int now;
        scanf("%d", &now);
        A[now] = i;
    }
    for (int i = 1; i <= m; i++)
    {
        int now;
        scanf("%d", &now);
        B[now] = i;
    }
    ll X, y;
    g = exgcd(n, m, X, y);
    exgcd(n / g, m / g, X, y);
    X %= (m / g);
    for (int i = 1; i <= 2 * max(n, m); i++)
    {
        A[i]--;
        B[i]--;
        if (A[i] == -1 || B[i] == -1)
            continue;
        if (abs(A[i] - B[i]) % g != 0)
            continue;
        // A[i]+nx=B[i]+my, nx-my=B-A
        v.push_back(i);
        ll x = X * (B[i] - A[i]) / g;
        x %= (m / g);
        if (x < 0)
            x += m / g;
        if (n * x < (B[i] - A[i]))
        {
            ll x_min = (B[i] - A[i] + n - 1) / n;
            ll times = (x_min - x + (m / g) - 1) / (m / g);
            x += times * (m / g);
            //printf("in\n");
        }
        st[i] = x;
        //printf("i=%d st=%lld\n", i, st[i]);
    }
    ll l = -1, r = LLONG_MAX - 5;
    while (r - l > 1)
    {
        ll mid = (l + r) / 2;
        if (C(mid) >= K)
            r = mid;
        else
            l = mid;
    }
    printf("%lld\n", r + 1);

    return 0;
}