#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
int main() {
  string s;
  string b[4];
  int ind = 0;
  for (int i = 1; i <= 3; i++) {
    string a;
    cin >> a;
    b[i] = a;
    if (i > 1) {
      if (a != s) ind = 1;
    }
    m[a]++;
    s = a;
  }
  if (ind == 0) {
    cout << 0;
    return 0;
  }
  int ans = 3;
  for (int i = 1; i <= 3; i++) {
    int ans1 = 3 - m[b[i]];
    int ans2 = 4;
    int x = b[i][0] - 48;
    int j = max(0, x - 2);
    for (; j <= x; j++) {
      char n = (j + 1) + 48;
      char l = (j + 48);
      char p = (j + 2) + 48;
      string s1 = "", s2 = "", s3 = "";
      s1 += l, s2 += n, s3 += p;
      s1 += b[i][1], s2 += b[i][1], s3 += b[i][1];
      int o = m[s1], y = m[s2], x = m[s3];
      x = min(1, x), o = min(o, 1), y = min(1, y);
      ans2 = min(ans2, 3 - (x + o + y));
    }
    ans = min(ans, min(ans1, ans2));
  }
  cout << ans;
  return 0;
}
