#include <bits/stdc++.h>
using namespace std;
long long a[100000];
map<long long, long long> mp;
map<long long, long long> mp1;
int main() {
  cin.sync_with_stdio(false);
  long long i, j, k, l, c, d, e, f, g, h, v, b[10000], aa[1009], bb[1000], n, m,
      r, t;
  long long x1, x2, y1, y2, x3, x4, x5, x6;
  string s, s1, s2 = "fedabc", s3, ss[10000];
  while (cin >> n) {
    cin >> s[0];
    c = 0;
    if (n % 4 == 1 || n % 4 == 2) {
      c = c + 16 * (n / 4);
      i = (n / 4) * 4 + 1;
      for (i;; i = i + 3) {
        if (i == n) {
          for (k = 0; k < 6; k++) {
            c++;
            if (s[0] == s2[k]) break;
          }
          cout << (c);
          return 0;
        } else {
          c += 6 + 1;
          for (j = i + 1; j <= (i + 1); j++) {
            if (j == n) {
              for (k = 0; k < 6; k++) {
                c++;
                if (s[0] == s2[k]) break;
              }
              cout << (c);
              return 0;
            }
            c += 3;
            i = j;
          }
        }
      }
    } else {
      m = n - 1;
      c = c + 16 * (m / 4);
      i = (m / 4) * 4 + 3;
      {
        for (i;; i = i + 3) {
          if (i == n) {
            for (k = 0; k < 6; k++) {
              c++;
              if (s[0] == s2[k]) break;
            }
            cout << (c);
            return 0;
          } else {
            c += 6 + 1;
            for (j = i + 1; j <= (i + 1); j++) {
              if (j == n) {
                for (k = 0; k < 6; k++) {
                  c++;
                  if (s[0] == s2[k]) break;
                }
                cout << (c);
                return 0;
              }
              c += 3;
              i = j;
            }
          }
        }
      }
    }
  }
}
