#include <iostream>
#include <cmath>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
string s;
int a, b, c;
int n, m, k;
vector<int>vec, vec2;
int arr[4000000], mark[4000000];
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n >> m >> k;
	for (int i = 0; i < n; i++) {
		cin >> a;
		vec.push_back(a);
	}
	for (int i = 0; i < m; i++) {
		cin >> a;
		vec2.push_back(a);
	}
	if (n < m) {
		swap(n, m);
		swap(vec, vec2);
	}
	int iter = 0;
	for (auto i : vec) {
		mark[iter] = m;
		iter++;
		arr[i] = iter;
	}
	iter = 0;
	int pos;
	for (auto i : vec2) {
		iter++;
		if (arr[i] != 0) {
			pos = (arr[i] - iter + n) % n;
			mark[pos]--;
		}
	}
	pos = 0;
	int sum = 0;
	int len = 0;
	while (true) {
		sum += mark[pos];
		pos += m;
		len += m;
		pos %= n;
		if (pos == 0) {
			break;
		}
	}
	k -= 2;
	int ans = (k / sum);
	ans *= len;
	k %= sum;
	k += 2;
	pos = 0;
	while (k > mark[pos]) {
		k -= mark[pos];
		pos += m;
		ans += m;
		pos %= n;
	}
	int pos2 = 0;
	while (k > 0) {
		ans++;
		if (vec[(pos + pos2) % n] != vec2[pos2 % m]) {
			k--;
		}
		pos2++;
	}
	cout << ans;
	return 0;
}