#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long powmod(long long a, long long l, long long md) {
  long long res = 1;
  while (l) {
    if (l & 1) res = res * a % md;
    l /= 2;
    a = a * a % md;
  }
  return res;
}
long long binpow(long long a, long long l) {
  long long res = 1;
  while (l) {
    if (l & 1) res = res * a;
    l /= 2;
    a = a * a;
  }
  return res;
}
long long __set(long long b, long long i) { return b | (1 << i); }
long long __unset(long long b, long long i) { return b & (~(1UL << i)); }
long long __check(long long b, long long i) { return b & (1 << i); }
long long mulmod(long long a, long long b, long long md) {
  return ((a % md) * (b % md)) % md;
}
long long addmod(long long a, long long b, long long md) {
  return (a + b) % md;
}
long long submod(long long a, long long b, long long md) {
  return (((a - b) % md) + md) % md;
}
long long divmod(long long a, long long b, long long md) {
  return mulmod(a, powmod(b, md - 2, md), md);
}
const long long inf = 0xFFFFFFFFFFFFFFFL;
priority_queue<long long, vector<long long>, greater<long long> > pq;
clock_t time_p = clock();
void time() {
  time_p = clock() - time_p;
  cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
long long d[3][10];
signed main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  for (long long i = 0; i < 3; i++) {
    string s;
    cin >> s;
    if (s[1] == 'm') {
      d[0][s[0] - '0']++;
    } else if (s[1] == 'p') {
      d[1][s[0] - '0']++;
    } else {
      d[2][s[0] - '0']++;
    }
  }
  long long mx = 3;
  for (long long i = 0; i < 3; i++) {
    for (long long j = 1; j <= 9; j++) mx = min(mx, 3 - min(3ll, d[i][j]));
    for (long long j = 1; j <= 7; j++) {
      long long tp = 0;
      if (!d[i][j]) tp++;
      if (!d[i][j + 1]) tp++;
      if (!d[i][j + 2]) tp++;
      mx = min(mx, tp);
    }
  }
  cout << mx << "\n";
  return 0;
}
