#include <bits/stdc++.h>
using namespace std;
bool sortbysecAsc(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second < b.second;
}
bool sortbyfirstAsc(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first < b.first;
}
bool sortbysecDesc(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second > b.second;
}
bool sortbyfirstDesc(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first > b.first;
}
int kingsA[8] = {0, 0, 1, -1, -1, 1, -1, 1};
int kingsB[8] = {-1, 1, 0, 0, 1, 1, -1, -1};
int main() {
  char a, b;
  cin >> a >> b;
  int am = a - 'a', pm = b - '0';
  int cnt = 0;
  am += 1;
  for (int i = 0; i < 8; i++) {
    if ((am + kingsA[i] >= 1 and am + kingsA[i] <= 8) and
        (pm + kingsB[i] >= 1 and pm + kingsB[i] <= 8))
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}
