#include "insects.h"
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
using namespace std;
const int MAX=2005;
bool V[MAX];
int min_cardinality(int N) {
int l=1,r=N;
while (l!=r){
int k=(l+r)/2;
fill_n(V,N,0);
for (int i=0;i<N;i++){
move_inside(i);
if (press_button()>k) V[i]=1,move_outside(i);
}
for (int i=0;i<N;i++) if (!V[i]) move_outside(i);
for (int i=0;i<N;i++) if (V[i]){
move_inside(i);
if (press_button()>1) move_outside(i);
}
for (int i=0;i<N;i++) if (!V[i]){
move_inside(i);
if (press_button()>1) move_outside(i),V[i]=1;
}
bool f=0;
for (int i=0;i<N;i++) if (!V[i]) f=1;
if (f) r=k;
else l=k+1;
}
return l;
}