#include <bits/stdc++.h>
using namespace std;
int main() {
  map<char, int> m;
  m['s'] = 0;
  m['m'] = 1;
  m['p'] = 2;
  string a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c) {
    cout << 0;
    return 0;
  }
  if (a == b || b == c || c == a) {
    cout << 1;
    return 0;
  }
  bool p[3][10];
  for (int i = 0; i < 10; i++) {
    p[1][i] = 0;
    p[2][i] = 0;
    p[0][i] = 0;
  }
  p[m[a[1]]][(int(a[0]) - '0')] = true;
  p[m[b[1]]][(int(b[0]) - '0')] = true;
  p[m[c[1]]][(int(c[0]) - '0')] = true;
  int ans = 2;
  int temp = 0;
  for (int j = 0; j <= 2; j++) {
    for (int i = 1; i <= 7; i++) {
      temp = 0;
      if (p[j][i]) temp++;
      if (p[j][i + 1]) temp++;
      if (p[j][i + 2]) temp++;
      if (temp == 3) {
        cout << "0";
        return 0;
      }
      if (temp == 2) ans = min(ans, 1);
    }
  }
  cout << ans;
}
