#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
class ANewHope { public:
int count(vector <int> firstWeek, vector <int> lastWeek, int D)
{
const int N = firstWeek.size();
const int s = N-D;
int worst = 0;
for(int v=1; v<=N; ++v) {
int a = find(firstWeek.begin(), firstWeek.end(), v) - firstWeek.begin();
int b = find(lastWeek.begin(), lastWeek.end(), v) - lastWeek.begin();
worst = max(worst, b==a ? 0 : b>a ? 1 : (a-b+s-1)/s);
}
return worst+1;
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
bool ok = (Expected == Received);
if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl;
cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END verify_case(_, ANewHope().count(firstWeek, lastWeek, D));}
int main(){
CASE(0)
int firstWeek_[] = {1,2,3,4};
vector <int> firstWeek(firstWeek_, firstWeek_+sizeof(firstWeek_)/sizeof(*firstWeek_));
int lastWeek_[] = {4,3,2,1};
vector <int> lastWeek(lastWeek_, lastWeek_+sizeof(lastWeek_)/sizeof(*lastWeek_));
int D = 3;
int _ = 4;
END
CASE(1)
int firstWeek_[] = {8,5,4,1,7,6,3,2};
vector <int> firstWeek(firstWeek_, firstWeek_+sizeof(firstWeek_)/sizeof(*firstWeek_));
int lastWeek_[] = {2,4,6,8,1,3,5,7};
vector <int> lastWeek(lastWeek_, lastWeek_+sizeof(lastWeek_)/sizeof(*lastWeek_));
int D = 3;
int _ = 3;
END
CASE(2)
int firstWeek_[] = {1,2,3,4};
vector <int> firstWeek(firstWeek_, firstWeek_+sizeof(firstWeek_)/sizeof(*firstWeek_));
int lastWeek_[] = {1,2,3,4};
vector <int> lastWeek(lastWeek_, lastWeek_+sizeof(lastWeek_)/sizeof(*lastWeek_));
int D = 2;
int _ = 1;
END
/*
CASE(3)
int firstWeek_[] = ;
vector <int> firstWeek(firstWeek_, firstWeek_+sizeof(firstWeek_)/sizeof(*firstWeek_));
int lastWeek_[] = ;
vector <int> lastWeek(lastWeek_, lastWeek_+sizeof(lastWeek_)/sizeof(*lastWeek_));
int D = ;
int _ = ;
END
CASE(4)
int firstWeek_[] = ;
vector <int> firstWeek(firstWeek_, firstWeek_+sizeof(firstWeek_)/sizeof(*firstWeek_));
int lastWeek_[] = ;
vector <int> lastWeek(lastWeek_, lastWeek_+sizeof(lastWeek_)/sizeof(*lastWeek_));
int D = ;
int _ = ;
END
*/
}
// END CUT HERE