#include <bits/stdc++.h>
using namespace std;
const int inf = 200009;
char str[inf];
char ord[] = {"fedabc"};
int main() {
  long long n;
  char c;
  cin >> n;
  cin >> c;
  n--;
  long long r = n / 4;
  r *= 16ll;
  if (n % 4 == 1 || n % 4 == 3) r += 7;
  r++;
  for (int i = 0; i < 6 && ord[i] != c; ++i, ++r)
    ;
  cout << r << endl;
}
