#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int r = s[1] - 48;
  int c = s[0] - 96;
  int m = 0;
  if ((r + 1) < 9 && (c - 1) > 0) m++;
  if ((r + 1) < 9) m++;
  if ((r + 1) < 9 && (c + 1) < 9) m++;
  if ((c - 1) > 0) m++;
  if ((c + 1) < 9) m++;
  if ((r - 1) > 0 && (c - 1) > 0) m++;
  if ((r - 1) > 0) m++;
  if ((r - 1) > 0 && (c + 1) < 9) m++;
  cout << m;
  return 0;
}
