#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
char str[maxn];
int main() {
  long long n;
  char c;
  cin >> n >> c;
  long long tmp = n / 4;
  long long gg = n % 4;
  if (gg == 0) tmp--, gg = 4;
  long long ans1 = 16 * tmp;
  long long ans2 = 0;
  if (gg == 1 || gg == 3) {
    if (c <= 'c') {
      ans2 = 3 + c - 'a' + 1;
    } else
      ans2 = -(c - 'f') + 1;
  } else {
    ans2 = 7;
    if (c <= 'c') {
      ans2 += 3 + c - 'a' + 1;
    } else
      ans2 += -(c - 'f') + 1;
  }
  long long ans = ans1 + ans2;
  cout << ans << endl;
  return 0;
}
