#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k = 0;
  char c;
  string s = "fedabc";
  cin >> n >> c;
  if (n % 2 != 0) {
    if ((n + 1) % 4 == 0) {
      k += n - 3;
      n -= 3;
    } else {
      k += n - 1;
      n -= 1;
    }
    k += 6 * (n / 2);
  } else {
    if (n % 4 == 0) {
      k += n - 3;
      n -= 2;
    } else {
      k += n - 1;
    }
    k += 6 * (n / 2);
  }
  cout << (long long)k + s.find(c) + 1;
  return 0;
}
