#include <bits/stdc++.h>
using namespace std;
enum Word {
bimm,
bamm,
bumm,
szam
};
int main() {
int length = 0;
cin >> length;
vector<Word> words(length, Word::szam);
for (int i = 0; i < length; i++) {
string input;
cin >> input;
if (input == "BIMM") words[i] = Word::bimm;
else if (input == "BAMM") words[i] = Word::bamm;
else if (input == "BUMM") words[i] = Word::bumm;
else words[i] = Word::szam;
}
for (int i = 0; i < length; i++) {
int j = i+1;
if (j % 3 != 0 && j % 5 != 0 && words[i] == Word::szam) continue;
else if (j % 3 == 0 && j % 5 != 0 && words[i] == Word::bimm) continue;
else if (j % 3 != 0 && j % 5 == 0 && words[i] == Word::bamm) continue;
else if (j % 3 == 0 && j % 5 == 0 && words[i] == Word::bumm) continue;
else {
cout << j << endl;
break;
}
}
return 0;
}