#include using namespace std; int main() { ios::sync_with_stdio(false); int n; char ch; int ret; while(scanf("%d %c\n", &n, &ch) == 2) { if(ch == 'K'){ if(n==1) ret = 1; else ret = 4; } if(ch == 'B' || ch == 'R'){ ret = n; } if(ch == 'N'){ if(n<=2) ret = 1; else ret = 2; } cout << ret << "\n"; } return 0; }