/*
#include <vector>
#include <iostream>
using namespace std;
vector<int> solution(vector<int> arr)
{
vector<int> answer;
for(int i=0; i<arr.size(); i++) {
if(i==0){
answer.push_back(arr[i]);
}
else{
if(arr[i-1]!=arr[i]){
answer.push_back(arr[i]);
}
}
}
return answer;
}
int main() {
vector<int> data;
data.push_back(1);
data.push_back(1);
data.push_back(3);
data.push_back(3);
data.push_back(0);
data.push_back(1);
data.push_back(1);
vector<int> result = solution(data);
for(int i=0; i<result.size(); i++) {
cout << result[i] <<endl ;
}
}
*/
/*
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> progresses, vector<int> speeds) {
vector<int> answer;
int k=0,dmax=0;
for(int i=0;i<progresses.size();i++)
{
if(dmax<(100-progresses[i]+speeds[i]-1)/speeds[i]){
dmax=(100-progresses[i]+speeds[i]-1)/speeds[i];
if(i!=0) answer.push_back(k);
k=1;
}
else{
k++;
}
}
answer.push_back(k);
return answer;
}
int main()
{
vector<int> progresses;
vector<int> speeds;
progresses.push_back(95);
progresses.push_back(90);
progresses.push_back(99);
progresses.push_back(99);
progresses.push_back(80);
progresses.push_back(99);
speeds.push_back(1);
speeds.push_back(1);
speeds.push_back(1);
speeds.push_back(1);
speeds.push_back(1);
speeds.push_back(1);
vector<int>result=solution(progresses,speeds);
for(int i=0;i<result.size();i++){
cout <<result[i]<<endl;
}
}
*/
/*
#include<string>
#include <iostream>
using namespace std;
bool solution(string s)
{
int check=0;
bool answer = true;
for(int i=0;i<s.size();i++)
{
if(s[i]=='('){
check++;
}
if(s[i]==')'){
if(check==0) answer=false;
else check--;
}
}
if(check!=0) answer=false;
return answer;
}
int main()
{
string s = ")()(";
bool result=solution(s);
cout<< result <<endl;
}
*/
#include<iostream>
#include <string>
#include <vector>
using namespace std;
int solution(vector<int> priorities, int location)
{
int answer = 0;
int first=0,count1=0,count2=1;
int k=priorities.size();
for(;;)
{
for(int i=first+1; i<priorities.size(); i++)
{
if(priorities[i]>priorities[first]){
priorities.push_back(priorities[first]);
first++;
count1=1;
}
}
if(count1==0){
if(first%k==location){
answer=count2;
return answer;
}
first++;
count2++;
}
count1=0;
}
}
int main()
{
vector<int> priorities;
int location=1;
priorities.push_back(1);
priorities.push_back(1);
priorities.push_back(1);
priorities.push_back(1);
priorities.push_back(1);
priorities.push_back(1);
int result=solution(priorities,location);
cout<<result<<endl;
}