#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n,k;
	cin>>n;
	int temp,temp2;
	string s="";
	int lol;
	for(temp=0;temp<n;temp++)
	{
		cin>>lol;
		s+=char(lol+48);
	}
	cin>>k;
	string target=s;
	sort(target.begin(),target.end());
	//cout<<target<<"\n";
	queue<pair<string,int>> q;
	q.push(make_pair(s,0));
	map<string,bool> visited;
	while(!q.empty())
	{
		string st=q.front().first;
		int cnt=q.front().second;
		q.pop();
		if(visited[st])	continue;
		visited[st]=true;
		if(st==target)
		{
			cout<<cnt<<"\n";
			return 0;
		}
		cnt++;
		for(temp=0;temp<=n-k;temp++)
		{
			string sst=st;
			int troll=0;
			for(temp2=temp;temp2<temp+k;temp2++)
			{
				sst[temp2]=st[temp+k-troll-1];
				troll++;
			}
			//cout<<sst<<" "<<cnt<<"\n";
			q.push(make_pair(sst,cnt));
		}
	}
	cout<<-1<<"\n";
}