#include <bits/stdc++.h>
using namespace std;
int d[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1},
               {0, 1},   {1, -1}, {1, 0},  {1, 1}};
inline bool inRange(int x) { return 1 <= x && x <= 8; }
int main() {
  int ans = 0;
  char c;
  int x, y;
  scanf("%c%d", &c, &y);
  x = c - 'a' + 1;
  for (int i = 0; i < 8; i++) {
    int xx = x + d[i][0], yy = y + d[i][1];
    if (inRange(xx) && inRange(yy)) ans++;
  }
  printf("%d\n", ans);
  return 0;
}
