#include <bits/stdc++.h>
using namespace std;
int s[15], p[15], m[15], ans, l, i, j, minim = 9;
string s1[5];
int main() {
  for (int i = 0; i < 3; ++i) {
    cin >> s1[i];
    if (s1[i][1] == 's') s[s1[i][0] - '0']++;
    if (s1[i][1] == 'p') p[s1[i][0] - '0']++;
    if (s1[i][1] == 'm') m[s1[i][0] - '0']++;
  }
  for (i = 1; i <= 9; i++) {
    if (s[i] == 3 || p[i] == 3 || m[i] == 3)
      ans = 0;
    else if ((s[i] == 1 && s[i + 1] == 1 && s[i + 2] == 1) ||
             (m[i] == 1 && m[i + 1] == 1 && m[i + 2] == 1) ||
             (p[i] == 1 && p[i + 1] == 1 && p[i + 2] == 1))
      ans = 0;
    else if (((s[i] == 1 && s[i + 1] == 1) || (s[i] == 1 && s[i + 2] == 1)) ||
             ((m[i] == 1 && m[i + 1] == 1) || (m[i] == 1 && m[i + 2] == 1)) ||
             ((p[i] == 1 && p[i + 1] == 1) || (p[i] == 1 && p[i + 2] == 1)) ||
             s[i] == 2 || m[i] == 2 || p[i] == 2)
      ans = 1;
    else
      ans = 2;
    if (ans < minim) minim = ans;
  }
  cout << minim;
  return 0;
}
