#include <bits/stdc++.h>
using namespace std;
char s[100];
pair<int, int> arr[10];
int ttt(char a) {
  if (a == 's') return 1;
  if (a == 'p') return 2;
  return 3;
}
int main() {
  gets(s);
  int pos = 0;
  for (int i = 1; i <= 3; i++) {
    int x = s[pos] - '0';
    pos++;
    int y = ttt(s[pos]);
    pos += 2;
    arr[i] = pair<int, int>(y, x);
  }
  sort(arr + 1, arr + 1 + 3);
  if (arr[1].first == arr[2].first && arr[2].first == arr[3].first) {
    if (arr[1].second == arr[2].second && arr[2].second == arr[3].second) {
      cout << "0" << endl;
      return 0;
    }
    if (arr[1].second + 1 == arr[2].second &&
        arr[2].second + 1 == arr[3].second) {
      cout << "0" << endl;
      return 0;
    }
  }
  if (arr[1].first == arr[2].first) {
    if (arr[1].second == arr[2].second) {
      cout << "1" << endl;
      return 0;
    }
    if (arr[1].second == arr[2].second - 1) {
      cout << "1" << endl;
      return 0;
    }
    if (arr[1].second == arr[2].second - 2) {
      cout << "1" << endl;
      return 0;
    }
  }
  if (arr[2].first == arr[3].first) {
    if (arr[3].second == arr[2].second) {
      cout << "1" << endl;
      return 0;
    }
    if (arr[3].second == arr[2].second + 1) {
      cout << "1" << endl;
      return 0;
    }
    if (arr[3].second == arr[2].second + 2) {
      cout << "1" << endl;
      return 0;
    }
  }
  cout << "2" << endl;
  return 0;
}
