#include <bits/stdc++.h>
using namespace std;
string s;
int c, r, ans = 0;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s;
  c = s[0] - 'a';
  r = s[1] - '1';
  int dr[] = {-1, 0, 1, 1, 1, 0, -1, -1};
  int dc[] = {1, 1, 1, 0, -1, -1, -1, 0};
  for (int i = 0; i < 8; ++i) {
    int c_ = c + dc[i];
    int r_ = r + dr[i];
    if (c_ >= 0 && r_ >= 0 && c_ < 8 && r_ < 8) ans++;
  }
  cout << ans << endl;
  return 0;
}
