#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  string a, b, c;
  cin >> a >> b >> c;
  vector<int> m(10, 0);
  vector<int> p(10, 0);
  vector<int> s(10, 0);
  if (a[1] == 'm') {
    m[a[0] - 48]++;
  } else if (a[1] == 'p') {
    p[a[0] - 48]++;
  } else if (a[1] == 's') {
    s[a[0] - 48]++;
  }
  if (b[1] == 'm') {
    m[b[0] - 48]++;
  } else if (b[1] == 'p') {
    p[b[0] - 48]++;
  } else if (b[1] == 's') {
    s[b[0] - 48]++;
  }
  if (c[1] == 'm') {
    m[c[0] - 48]++;
  } else if (c[1] == 'p') {
    p[c[0] - 48]++;
  } else if (c[1] == 's') {
    s[c[0] - 48]++;
  }
  bool flag0 = false;
  bool flag1 = false;
  for (int i = 1; i < 8; i++) {
    if ((m[i] > 0 && m[i + 1] > 0 && m[i + 2]) ||
        (p[i] > 0 && p[i + 1] > 0 && p[i + 2]) ||
        (s[i] > 0 && s[i + 1] > 0 && s[i + 2])) {
      flag0 = true;
    }
    if ((m[i] > 0 && m[i + 2] > 0) || (p[i] > 0 && p[i + 2] > 0) ||
        (s[i] > 0 && s[i + 2] > 0)) {
      flag1 = true;
    }
  }
  for (int i = 1; i < 9; i++) {
    if ((m[i] > 0 && m[i + 1] > 0) || (p[i] > 0 && p[i + 1] > 0) ||
        (s[i] > 0 && s[i + 1] > 0)) {
      flag1 = true;
    }
  }
  for (int i = 1; i < 10; i++) {
    if (m[i] == 3 || p[i] == 3 || s[i] == 3) flag0 = true;
    if (m[i] == 2 || p[i] == 2 || s[i] == 2) flag1 = true;
  }
  if (flag0) {
    cout << 0;
    return 0;
  } else if (flag1) {
    cout << 1;
    return 0;
  } else {
    cout << 2;
    return 0;
  }
  return 0;
}
