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