#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define ud unsigned int
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x3f
#define MAX_INF_VAL 0x3f3f3f3f
#define MAX_INF_VAL_LL 0x3f3f3f3f3f3f3f3f
//#define pi 3.141592653589
#define eps 1e-9
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
//#define p 2173412051LL
//#define sz 2

using namespace std;

template< typename T > void read( T &x ) {
	x = 0;
	char ch = getchar();
	ll f = 1;
	while( !isdigit( ch ) ) {
		if( ch == '-' )
		f *= -1;
		ch = getchar();
	}
	while( isdigit( ch ) ) {
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	x *= f;
}

struct custom_hash {
    static uint64_t splitmix64( uint64_t x ) {
        x += 0x9e3779b97f4a7c15;
        x = ( x ^ ( x >> 30 ) ) * 0xbf58476d1ce4e5b9;
        x = ( x ^ ( x >> 27 ) ) * 0x94d049bb133111eb;
        return x ^ ( x >> 31 );
    }

    size_t operator() ( uint64_t x ) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64( x + FIXED_RANDOM );
    }
};

int n, m;
ll k;
bool vis[ 1000010 ];
int a[ 1000010 ], b[ 1000010 ];
int cir_id[ 1000010 ], st_id[ 1000010 ];
int len[ 1000010 ], len2[ 1000010 ];
int	ids[ 1000010 ], ids2[ 1000010 ];

bool check( ll );

int main() {
	ios::sync_with_stdio( false );
	cin.tie( 0 ), cout.tie( 0 );
	cin >> n >> m >> k;
	for( int i = 1; i <= n; ++i )
		cin >> a[ i ];
	for( int i = 1; i <= m; ++i )
		cin >> b[ i ];
	if( n > m ) {
		swap( n, m );
		swap( a, b );
	}
	for( int i = 1; i <= n; ++i ) {
		if( vis[ i ] )
			continue;
		int j = i;
		int st = 0;
		while( !vis[ j ] ) {
			vis[ j ] = true;
			cir_id[ j ] = i;
			st_id[ j ] = ++st;
			++len2[ i ];
			ids2[ b[ j ] ] = j;
			j += n;
			if( j > m )
				j -= m;
		}
	}
	for( int i = 1; i <= n; ++i ) {
		ids[ i ] = ids2[ a[ i ] ];
		len[ i ] = len2[ cir_id[ i ] ];
	}
	ll l = 1, r = 1e18;
	while( l <= r ) {
		ll mid = l + r >> 1;
		if( check( mid ) )
			r = mid - 1;
		else
			l = mid + 1;
	}
	cout << l;
	return 0;
}

bool check( ll x ) {
	ll res = 0;
	for( int i = 1; i <= n; ++i ) {
		ll tmp = x - i + 1;
		if( tmp <= 0 )
			break;
		int _len = len[ i ];
		ll tot = ( tmp + n - 1 ) / n;
		ll full = tot / _len;
		ll mod = tot % _len;
		res += tot;
		int fk = ids[ i ];
		if( fk ) {
			if( cir_id[ fk ] != cir_id[ i ] )
				continue;
			int tmp = st_id[ fk ];
			res -= full;
			if( mod == 0 )
				continue;
			int st = st_id[ i ], ed = st + mod - 1;
			if( ed <= _len ) {
				if( tmp >= st && tmp <= ed )
					--res;
			} else {
				ed -= _len;
				if( tmp >= st || tmp <= ed )
					--res;
			}
		}
	}
	return res >= k;
}