#include <bits/stdc++.h>
using namespace std;
char s[2];
long long solve(char c) {
  if (c == 'f') return 1;
  if (c == 'e') return 2;
  if (c == 'd') return 3;
  if (c == 'a') return 4;
  if (c == 'b') return 5;
  if (c == 'c') return 6;
}
int main() {
  long long p;
  while (~scanf("%lld%s", &p, s)) {
    long long ans = 0;
    ans += (p - 1) / 4 * 16;
    p %= 4;
    if (p == 1 || p == 3)
      ans += solve(s[0]);
    else
      ans += solve(s[0]) + 7;
    printf("%lld\n", ans);
  }
  return 0;
}
