#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  char x, y, z;
  cin >> a >> x >> b >> y >> c >> z;
  if (x != y && x != z && y != z) {
    cout << 2 << endl;
  } else if (x == y && y != z) {
    if (abs(a - b) == 1 || abs(a - b) == 2)
      cout << 1 << endl;
    else if (a == b)
      cout << 1 << endl;
    else
      cout << 2 << endl;
  } else if (x == z && z != y) {
    if (abs(a - c) == 1 || abs(a - c) == 2)
      cout << 1 << endl;
    else if (a == c)
      cout << 1 << endl;
    else
      cout << 2 << endl;
  } else if (z == y && x != z) {
    if (abs(c - b) == 1 || abs(c - b) == 2)
      cout << 1 << endl;
    else if (c == b)
      cout << 1 << endl;
    else
      cout << 2 << endl;
  } else {
    int temp;
    if (a > b) {
      temp = a;
      a = b;
      b = temp;
    }
    if (a > c) {
      temp = a;
      a = c;
      c = temp;
    }
    if (b > c) {
      temp = b;
      b = c;
      c = temp;
    }
    if ((a + c == 2 * b && b - a == 1) || (a == b && b == c))
      cout << "0" << endl;
    else if (abs(b - a) == 2 || abs(b - c) == 2 || abs(b - a) == 1 ||
             abs(b - c) == 1)
      cout << 1 << endl;
    else if (a == b || b == c)
      cout << 1 << endl;
    else
      cout << 2 << endl;
  }
}
