#include <bits/stdc++.h>
using namespace std;
int a[5];
char c[4];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i < 3; i++) {
    cin >> c;
    a[i] = c[0] - '0' + (c[1] - 'a') * 10;
  }
  sort(a, a + 3);
  int t1 = a[1] - a[0], t2 = a[2] - a[1], t3 = a[2] - a[0];
  if (t1 == 0 && t2 == 0) {
    cout << 0;
    return 0;
  } else if (t1 == 1 && t2 == 1) {
    cout << 0;
    return 0;
  } else if (t1 == 2 || t2 == 2) {
    cout << 1;
    return 0;
  } else if (t1 == 1 || t2 == 1) {
    cout << 1;
    return 0;
  } else if (t1 == 0 || t2 == 0) {
    cout << 1;
    return 0;
  } else
    cout << 2;
  return 0;
}
