#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<vector<int>> b(9);
  for (int i = 0; i < 9; i++)
    for (int j = 0; j < 3; j++) b[i].push_back(0);
  string s;
  for (int i = 0; i < 3; i++) {
    cin >> s;
    switch (s[1]) {
      case 'm':
        b[s[0] - '1'][0]++;
        break;
      case 'p':
        b[s[0] - '1'][1]++;
        break;
      case 's':
        b[s[0] - '1'][2]++;
        break;
    }
  }
  int m = 0;
  for (int i = 0; i < 9; i++) {
    int s1 = b[i][0];
    int s2 = b[i][1];
    int s3 = b[i][2];
    m = min(max(max(max(s1, s2), s3), m), 3);
  }
  for (int i = 0; i < 7; i++) {
    int s1 = (b[i][0] != 0) + (b[i + 1][0] != 0) + (b[i + 2][0] != 0);
    int s2 = (b[i][1] != 0) + (b[i + 1][1] != 0) + (b[i + 2][1] != 0);
    int s3 = (b[i][2] != 0) + (b[i + 1][2] != 0) + (b[i + 2][2] != 0);
    m = max(max(max(s1, s2), s3), m);
  }
  cout << 3 - m;
}
