#include <bits/stdc++.h>
using namespace std;
template <class T>
T &get(T &n) {
  cin >> n;
  return n;
}
int main() {
  int T, N, i, j;
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long row;
  char col;
  cin >> row >> col;
  row--;
  col -= 'a';
  long long ans = 0;
  ans += (row / 4) * 16;
  row %= 4;
  vector<int> order = {5, 4, 3, 0, 1, 2};
  vector<vector<int>> matrix(4, vector<int>(6));
  int time = 0;
  for (auto it = (order).begin(); it != (order).end(); it++) {
    ++time;
    matrix[0][*it] = time;
    matrix[2][*it] = time;
  }
  time++;
  for (auto it = (order).begin(); it != (order).end(); it++) {
    ++time;
    matrix[1][*it] = time;
    matrix[3][*it] = time;
  };
  ans += matrix[row][col];
  cout << ans << endl;
  return 0;
}
