#include <bits/stdc++.h>
using namespace std;
int main() {
  long long num, m, tc, t = 1;
  int arr[3];
  for (long long i = 0; i < 3; i++) {
    char ch;
    cin >> num >> ch;
    if (ch == 'm')
      arr[i] = num + 100;
    else if (ch == 'p')
      arr[i] = num + 200;
    else
      arr[i] = num + 300;
  }
  sort(arr, arr + 3);
  if (arr[0] == arr[1] && arr[1] == arr[2]) {
    cout << "0" << endl;
  } else if (arr[0] + 1 == arr[1] && arr[1] + 1 == arr[2]) {
    cout << "0" << endl;
  } else if (arr[0] == arr[1] || arr[1] == arr[2] || arr[0] + 1 == arr[1] ||
             arr[1] + 1 == arr[2] || arr[0] + 2 == arr[1] ||
             arr[1] + 2 == arr[2]) {
    cout << "1" << endl;
  } else
    cout << "2" << endl;
}
