#include <bits/stdc++.h>
using namespace std;
long long smallest(long long x, long long y, long long z) {
  long long c = 0;
  while (x && y && z) {
    x--;
    y--;
    z--;
    c++;
  }
  return c;
}
long long smallest(long long x, long long y) { return (x < y) ? x : y; }
void solve() {
  string input[3];
  long long countType1 = 0;
  long long countType2 = 0;
  long long countType3 = 0;
  for (long long i = 0; i < 3; i++) cin >> input[i];
  long long count = 0;
  if (input[1] == input[0]) {
    if (input[2] == input[1]) {
      count = 3;
    } else
      count = 2;
  } else {
    if (input[1] == input[2] || input[0] == input[2]) {
      count = 2;
    } else
      count = 1;
  }
  if (countType1 == 2) {
    cout << 0 << endl;
  } else {
    long long moreReqd[3][3];
    vector<long long> k(3, 0);
    for (long long i = 0; i < 3; i++) {
      if (input[i][1] == 'm') {
        moreReqd[0][k[0]++] = input[i][0];
      } else if (input[i][1] == 'p') {
        moreReqd[1][k[1]++] = input[i][0];
      } else {
        moreReqd[2][k[2]++] = input[i][0];
      }
    }
    sort(moreReqd[0], moreReqd[0] + k[0]);
    sort(moreReqd[1], moreReqd[1] + k[1]);
    sort(moreReqd[2], moreReqd[2] + k[2]);
    long long maxi = INT_MIN;
    for (long long i = 0; i < 3; i++) {
      if (k[i] == 0) {
      } else if (k[i] == 1) {
        if (maxi < 1) {
          maxi = 1;
        }
      } else if (k[i] == 2) {
        if (moreReqd[i][1] - moreReqd[i][0] > 2) {
          if (maxi < 1) {
            maxi = 1;
          }
        } else {
          if (maxi < 2) {
            maxi = 2;
          }
        }
      } else {
        if (moreReqd[i][0] == moreReqd[i][1] - 1 &&
            moreReqd[i][0] == moreReqd[i][2] - 2) {
          maxi = 3;
          break;
        } else if (moreReqd[i][0] == moreReqd[i][1] - 1 ||
                   moreReqd[i][0] == moreReqd[i][1] - 2 ||
                   moreReqd[i][1] == moreReqd[i][2] - 1 ||
                   moreReqd[i][1] == moreReqd[i][2] - 2) {
          if (maxi < 2) maxi = 2;
        } else if (moreReqd[i][0] == moreReqd[i][1] &&
                       moreReqd[i][2] - moreReqd[i][0] <= 2 ||
                   moreReqd[i][1] == moreReqd[i][2] &&
                       moreReqd[i][2] - moreReqd[i][0] <= 2) {
          if (maxi < 2) {
            maxi = 2;
          }
        } else {
          if (maxi < 1) maxi = 1;
        }
      }
    }
    long long min2 = 3 - maxi;
    long long min1 = 3 - count;
    cout << min({min1, min2}) << endl;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
