#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  ios_base::sync_with_stdio(false);
  solve();
  return 0;
}
void solve() {
  string a, b, c;
  cin >> a >> b >> c;
  vector<int> arr;
  arr.push_back(a[0]);
  arr.push_back(b[0]);
  arr.push_back(c[0]);
  if (a[1] == b[1] && a[1] == c[1]) {
    if (arr[0] == arr[1] && arr[0] == arr[2])
      cout << 0 << endl;
    else if (arr[0] == arr[1] || arr[1] == arr[2] || arr[0] == arr[2]) {
      cout << 1 << endl;
    } else {
      int min = 4;
      sort(arr.begin(), arr.end());
      for (int i = 0; i < 2; ++i) {
        if ((arr[i + 1] - arr[i]) < min) min = arr[i + 1] - arr[i];
      }
      if (min == 3 || min == 4)
        cout << 2 << endl;
      else if (min == 2)
        cout << 1 << endl;
      else {
        if (arr[1] == (arr[0] + 1) && arr[2] == (arr[1] + 1))
          cout << 0 << endl;
        else
          cout << 1 << endl;
      }
    }
  } else if (a[1] == b[1] || a[1] == c[1] || c[1] == b[1]) {
    if (a[1] == b[1]) {
      int temp = abs(a[0] - b[0]);
      if (temp == 0 || temp == 1 || temp == 2)
        cout << 1 << endl;
      else
        cout << 2 << endl;
    } else if (a[1] == c[1]) {
      int temp = abs(a[0] - c[0]);
      if (temp == 0 || temp == 1 || temp == 2)
        cout << 1 << endl;
      else
        cout << 2 << endl;
    } else {
      int temp = abs(b[0] - c[0]);
      if (temp == 0 || temp == 1 || temp == 2)
        cout << 1 << endl;
      else
        cout << 2 << endl;
    }
  } else {
    cout << 2 << endl;
  }
}
