#include <bits/stdc++.h>
using namespace std;
char c[10] = {'?', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', '?'};
int d[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  char ch;
  int D;
  cin >> ch >> D;
  int C = ch - 'a' + 1;
  int ans = -1;
  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      int tC = C + i;
      int tD = D + j;
      if (('a' <= c[tC] && c[tC] <= 'h') && (1 <= d[tD] && d[tD] <= 8)) {
        ans++;
      }
    }
  }
  cout << ans << "\n";
}
