#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
constexpr int N = 1e3 + 5;
int a, b, ans = -1;
char v;
void Solve() {
  cin >> v;
  a = v - 'a';
  cin >> v;
  b = v - '1';
  for (int i = -1; i < 2; i++)
    for (int j = -1; j < 2; j++) {
      ans += (a + i >= 0 && a + i < 8 && b + j >= 0 && b + j < 8);
    }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  Solve();
  return 0;
}
