#include <bits/stdc++.h>
using namespace std;
int main() {
  string s[3];
  cin >> s[0] >> s[1] >> s[2];
  if (s[0][0] > s[1][0]) swap(s[0], s[1]);
  if (s[0][0] > s[2][0]) swap(s[0], s[2]);
  if (s[1][0] > s[2][0]) swap(s[2], s[1]);
  if (s[0] == s[1] and s[1] == s[2]) {
    cout << 0;
    return 0;
  } else if (s[0] == s[1] or s[1] == s[2]) {
    cout << 1;
    return 0;
  } else if (s[0][1] == s[1][1] and s[1][1] == s[2][1]) {
    if (s[2][0] - s[1][0] == 1 and s[1][0] - s[0][0] == 1) {
      cout << 0;
      return 0;
    } else if (s[2][0] - s[1][0] == 1 or s[1][0] - s[0][0] == 1) {
      cout << 1;
      return 0;
    } else if (s[2][0] - s[1][0] == 2 or s[1][0] - s[0][0] == 2) {
      cout << 1;
      return 0;
    } else {
      cout << 2;
      return 0;
    }
  } else if (s[0][1] == s[1][1]) {
    int temp = abs(s[0][0] - s[1][0]);
    if (temp == 1 or temp == 2) {
      cout << 1;
      return 0;
    } else {
      cout << 2;
      return 0;
    }
  } else if (s[1][1] == s[2][1]) {
    int temp = abs(s[1][0] - s[2][0]);
    if (temp == 1 or temp == 2) {
      cout << 1;
      return 0;
    } else {
      cout << 2;
      return 0;
    }
  } else if (s[0][1] == s[2][1]) {
    int temp = abs(s[0][0] - s[2][0]);
    if (temp == 1 or temp == 2) {
      cout << 1;
      return 0;
    } else {
      cout << 2;
      return 0;
    }
  } else {
    cout << 2;
    return 0;
  }
}
