#include <bits/stdc++.h>
using namespace std;
long long n, ans, ANS, N;
char c;
int main() {
  scanf("%I64d%c", &n, &c);
  n--;
  if (n > 1000000000000000l) {
    N = n / 1000000000000000l;
    ANS = N * 4;
    n %= 1000000000000000l;
  }
  ans += (n / 4) * 16;
  n %= 4;
  if (n % 2) ans += 7;
  string s = "fedabc";
  for (int i = 0; i < s.size(); i++)
    if (c == s[i]) ans += i + 1;
  ANS += ans / 1000000000000000l;
  ans %= 1000000000000000l;
  if (ANS > 0) {
    cout << ANS;
    long long t = ans, cnt = 0;
    while (t) {
      t /= 10;
      cnt++;
    }
    for (int i = 0; i < 15 - cnt; i++) cout << 0;
  }
  cout << ans;
  return 0;
}
