#include <bits/stdc++.h>

using namespace std;

typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
typedef ptrdiff_t isize;

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef size_t usize;

typedef float f32;
typedef double f64;


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

auto main() -> i32 {

    ios::sync_with_stdio(false), cin.tie(nullptr);

    i64 n, m, k;
    cin >> n >> m >> k;
    vector<i64> a(max(n, m) + 1);
    i64 M = 2 * max(n, m);
    vector<i64> p(M + 1, -1);

    if (n <= m) {
        for (i64 i = 1; i <= n; i++) {
            cin >> a[i];
        }


        for (i64 i = 1; i <= m; i++) {
            i64 b;
            cin >> b;
            p[b] = i;
        }
    }
    else {
        swap(n, m);


        for (i64 i = 1; i <= m; i++) {
            i64 b;
            cin >> b;
            p[b] = i;
        }
        for (i64 i = 1; i <= n; i++) {
            cin >> a[i];
        }

    }
    vector<i64> min_rnd(n + 1, -1);
    i64 g; {
        i64 x, y;
        g = gcd(n, m, x, y);
    }
    i64 lcm = m / g;

    for (i64 i = 1; i <= n; i++) {
        if (p[a[i]] != -1) {
            i64 dif = 0;
            if (i > p[a[i]]) {
                dif = p[a[i]] + m - i;
            }
            else {
                dif = p[a[i]] - i;
            }

            if (dif % g == 0) {
                dif /= g;
                i64 x, y;
                gcd(n / g, m / g, x, y);
                x = (x % lcm + lcm) % lcm;
                min_rnd[i] = (x * dif) % (lcm)+1;
            }
        }
    }

    i64 l = 1, r = 1e18 + 1;
    while (l < r) {
        i64 d = (l + r) / 2;
        i64 bad = 0;
        {
            for (i64 i = 1; i <= n; i++) {
                i64 rnd = d / n + (d % n >= i ? 1 : 0);
                if (min_rnd[i] != -1) {
                    bad += rnd - rnd / lcm - ((rnd % lcm) >= min_rnd[i] ? 1 : 0);
                }
                else {
                    bad += rnd;
                }
            }

        }

        if (bad >= k) {
            r = d;
        }
        else if (bad < k) {
            l = d + 1;
        }
    }

    cout << l;

    cout << "\n";

    return 0;
}
