#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  char m;
  scanf("%lld%c", &n, &m);
  long long ans = 0;
  --n;
  long long times = n / 4;
  ans += times * 4;
  ans += times * 2 * 6;
  long long left = n - times * 4;
  if (left == 1 || left == 3) ans += 1 + 6;
  if (m > 'c')
    ans += 1 + 'f' - m;
  else
    ans += 4 + m - 'a';
  printf("%lld\n", ans);
  return 0;
}
