# for t in range(int(input())):
#     s = input()
#     i, j = 0, 0
#     cnt = 0
#     ans = float('inf')
#     dic = {}
#     while j < len(s):
#         if len(dic) < 3:
#             dic[s[j]] = dic.get(s[j], 0) + 1
#         # print(j)
#         # print(dic)
#         while len(dic) == 3:
#             ans = min(ans, j - i + 1)
#             dic[s[i]] -= 1
#             if dic[s[i]] == 0:
#                 del dic[s[i]]
#             i += 1
#
#         j += 1
#     print((0, ans)[ans < float('inf')])

# for t in range(int(input())):
#     n = int(input())
#     s = list(map(int, input().split()))
#     dp = [1] * n
#     for i in range(n):
#         k = 2
#         while (i + 1) * k <= n:
#             j = (i + 1) * k
#             if s[i] < s[j - 1]:
#                 dp[j - 1] = max(dp[j - 1], dp[i] + 1)
#             k += 1
#     print(max(dp))

# for T in range(int(input())):
#     t = input()
#     z, o = 0, 0
#     for ch in t:
#         z = z + 1 if ch == '0' else z
#         o = o + 1 if ch == '1' else o
#     if z > 0 and o > 0:
#         print('01' * len(t))
#     elif o > 0 and not z:
#         print('1' * len(t))
#     else:
#         print('0' * len(t))

# for t in range(int(input())):
#     n = int(input())
#     a = list(map(int, input().split()))
#     a.sort()
#     ans = []
#     while a:
#         ans.append(str(a.pop(len(a) // 2)))
#     print(' '.join(ans))

# for t in range(int(input())):
#     n = int(input())
#     a = list(map(int, input().split()))
#     cnt = 0
#     p = set()
#     l, r = 0, sum(a)
#     left, right = {}, {}
#     for i in a:
#         right[i] = right.get(i, 0) + 1
#     for i in range(n - 1):
#         l += a[i]
#         left[a[i]] = left.get(a[i], 0) + 1
#         r -= a[i]
#         right[a[i]] = right.get(a[i], 0) - 1
#         if not right[a[i]]:
#             del right[a[i]]
#         j = n - i - 1
#         if (2 + i) * (i + 1) // 2 == l and (j + 1) * j // 2 == r:
#             if len(left) == i + 1 and len(right) == j:
#                 cnt += 1
#                 p.add((i + 1, n - i - 1))
#     print(cnt)
#     if cnt:
#         for el in p:
#             print(*el)

# for t in range(int(input())):
#     n = int(input())
#     G = []
#     taken = [False] * n
#     girl = -1
#     for i in range(n):
#         g = list(map(int, input().split()))
#         k = g[0]
#         single = True
#         for j in range(1, k + 1):
#             if not taken[g[j] - 1]:
#                 taken[g[j] - 1] = True
#                 single = False
#                 break
#         if single:
#             girl = i
#     if girl == -1:
#         print('OPTIMAL')
#     else:
#         print('IMPROVE')
#         print(girl + 1, taken.index(False) + 1)

# for t in range(int(input())):
#     n = int(input())
#     a = list(map(int, input().split()))
#     odd, even = [], []
#     for i in range(2 * n):
#         if a[i] % 2:
#             odd.append(i + 1)
#         else:
#             even.append(i + 1)
#     for i in range(n - 1):
#         if len(odd) >= len(even):
#             print(odd.pop(), odd.pop())
#         else:
#             print(even.pop(), even.pop())

# for t in range(int(input())):
#     n = int(input())
#     a = list(map(int, input().split()))
#     a.sort()
#     ans, i, j = 0, 0, 1
#     while j < n:
#         if a[i] < a[j]:
#             ans += 1
#             i += 1
#             j += 1
#         else:
#             while j < n and a[i] == a[j]:
#                 i += 1
#                 j += 1
#     print(ans + 1)

# for t in range(int(input())):
#     n = int(input())
#     a = list(map(int, input().split()))
#     got = False
#
#     b = 1
#     while not got and b < 2 * n - 1:
#         if b % 2:
#             i, j = (b - 1) // 2, (b + 1) // 2
#         else:
#             i, j = b // 2 - 1, b // 2 + 1
#         left, right = set(a[:i]), set(a[j:])
#         if left & right:
#             got = True
#         b += 1
#     print('YES' if got else 'NO')

# n, m, k = list(map(int, input().split()))
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# ans = 0
# a, b = [0], [0]
# for el in A:
#     a.append(a[-1] + el)
# for el in B:
#     b.append(b[-1] + el)
# d = [(i, k//i) for i in range(1, int(k**0.5)+1) if k % i == 0]
# d += [(j, i) for i, j in d if i != j]
# for i in range(n):
#     for j in range(m):
#         for q, p in d:
#             if i + q <= n and j + p <= m:
#                 if a[i + q] - a[i] == q and b[j + p] - b[j] == p:
#                     ans += 1
# print(ans)

# for t in range(int(input())):
#     n = int(input())
#     s = input()
#     dic, se = {s: 1}, {s}
#     for k in range(2, n):
#         p = s[k - 1:] + (s[:k - 1], s[:k - 1][::-1])[(n % 2) == (k % 2)]
#         # print(k, p)
#         if p not in dic:
#             # print(dic, p)
#             dic[p] = k
#             se.add(p)
#     if s[::-1] not in dic:
#         dic[s[::-1]] = n
#         se.add(s[::-1])
#     # print(dic)
#     ans = min(se)
#     print(ans)
#     print(dic[ans])

# for t in range(int(input())):
#     a, b, p = list(map(int, input().split()))
#     s = input()
#     road = [a if s[0] == 'A' else b]
#     st = [0]
#     for i in range(1, len(s) - 1):
#         if s[i] != s[i - 1]:
#             road.append(road[-1] + (a, b)[s[i] == 'B'])
#             st.append(i)
#     # print(road)
#     pay = road[-1]
#     j = 0
#     while pay > p and j < len(st):
#         pay = road[-1] - road[j]
#         j += 1
#     # print(j)
#     print(st[j] + 1 if j < len(st) else len(s))

# for t in range(int(input())):
#     n, x, y = list(map(int, input().split()))
#     print(max(1, min(x + y - n + 1, n)), min(n, x + y - 1))

# for t in range(int(input())):
#     n = int(input())
#     a = list(map(int, input().split()))
#     print(' '.join(map(str, sorted(a, reverse=True))))

# s = input()
# open, close = [], []
# i = 0
# for i in range(len(s)):
#     if s[i] == '(':
#         open.append(i)
#     else:
#         close.append(i)
# i, j = 0, len(close) - 1
# ans = []
# while i < len(open) and j >= 0 and open[i] < close[j]:
#     ans += [open[i] + 1, close[j] + 1]
#     i += 1
#     j -= 1
# ans.sort()
# print('0' if not ans else '1\n{}\n{}'.format(len(ans), ' '.join([str(idx) for idx in ans])))

import collections
# n, m = list(map(int, input().split()))
# a = list(input() for i in range(n))
# dic = {}
# for w in a:
#     dic[w] = dic.get(w, 0) + 1
# l, r = '', ''
# for i in range(n):
#     for j in range(i + 1, n):
#         # print(i, j, a)
#         if a[i] == a[j][::-1] and dic[a[i]] and dic[a[j]]:
#             l += a[i]
#             r = a[j] + r
#             dic[a[i]] -= 1
#             dic[a[j]] -= 1
# c = ''
# for k, v in dic.items():
#     if v and k == k[::-1]:
#         if c and c[-m] == k or not c:
#             c += k
# print(f'{len(l) + len(c) + len(r)}\n{l + c + r}')

# for t in range(int(input())):
#     n, g, b = list(map(int, input().split()))
#     d = n // 2 + n % 2
#     full, inc = divmod(d, g)
#     ans = (g + b) * (full - 1, full)[inc > 0] + (g, inc)[inc > 0]
#     print(ans if ans >= n else n)

# for t in range(int(input())):
#     n = int(input())
#     a = list(map(int, input().split()))
#     a.sort()
#     print(a[n] - a[n - 1])

# for t in range(int(input())):
#     n, x = list(map(int, input().split()))
#     s = input()
#     cntz = s.count('0')
#     total = 2 * cntz - n
#     bal = 0
#     ans = 0
#     for i in range(n):
#         if not total:
#             if bal == x:
#                 ans = -1
#         elif not abs(x - bal) % abs(total):
#             if (x - bal) // total >= 0:
#                 ans += 1
#         bal += 1 if s[i] == '0' else -1
#     print(ans)

# n = int(input())
# ans = 0
# for i in range(1, n + 1):
#     ans += 1 / i
# print(ans)

# for t in range(int(input())):
#     n = int(input())
#     a = list(map(int, input().split()))
#     p, s = 0, n - 1
#     for i in range(n):
#         if a[i] < i:
#             break
#         p = i
#     for i in range(n - 1, -1, -1):
#         if a[i] < n - i - 1:
#             break
#         s = i
#     print('Yes' if s <= p else 'No')

# n, k = list(map(int, input().split()))
# a = [input() for i in range(n)]
# c = set(a)
# b = set()
# for i in range(n):
#     for j in range(i + 1, n):
#         third = ''
#         for c1, c2 in zip(a[i], a[j]):
#             if c1 == c2:
#                 third += c1
#             else:
#                 if c1 != 'S' and c2 != 'S':
#                     third += 'S'
#                 elif c1 != 'E' and c2 != 'E':
#                     third += 'E'
#                 else:
#                     third += 'T'
#         if third in c:
#             b.add(frozenset([a[i], a[j], third]))
# print(len(b))

# for t in range(int(input())):
#     n = int(input())
#     a = list(map(int, input().split()))
#     total, curr = sum(a), 0
#     ans, i, start = 'YES', 0, 0
#     while ans == 'YES' and i < n:
#         if curr > 0:
#             curr += a[i]
#         else:
#             curr = a[i]
#             start = i
#         # print(curr, i, start, total)
#         if i - start + 1 < n and curr >= total:
#             ans = 'NO'
#         i += 1
#     print(ans)

# for t in range(int(input())):
#     n, p, k = list(map(int, input().split()))
#     a = list(map(int, input().split()))
#     a.sort(reverse=True)
#     odd, even = 0, 0
#     i, j = len(a) - 1, len(a) - 2
#     curr = 0
#     while curr < p and i >= 0:
#         curr += a[i]
#         if curr <= p:
#             odd += 1
#         i -= 2
#     curr = 0
#     while curr < p and j >= 0:
#         curr += a[j]
#         if curr <= p:
#             even += 1
#         j -= 2
#     print(max(odd * 2 - 1, even * 2))

# for t in range(int(input())):
#     s, c = input().split()
#     s = list(ch for ch in s)
#     sor = sorted(s)
#     for i in range(len(s)):
#         if s[i] != sor[i]:
#             j = max(j for j, v in enumerate(s[i:], i) if v == sor[i])
#             s = s[:i] + [s[j]] + s[i + 1:j] + [s[i]] + s[j + 1:]
#             break
#     s = ''.join(s)
#     print(s if s < c else '---')

# for t in range(int(input())):
#     n, s = list(map(int, input().split()))
#     a = list(map(int, input().split()))
#     if sum(a) <= s:
#         print(0)
#     else:
#         curr, i, j = 0, 0, 0
#         for i in range(n):
#             if a[i] > a[j]:
#                 j = i
#             s -= a[i]
#             if s < 0:
#                 break
#         print(j + 1)

# for t in range(int(input())):
#     a, b = list(map(int, input().split()))
#     a, b = (b, a) if b > a else (a, b)
#     if not ((1 + 8 * (a - b))**0.5 - 1) % 2 and ((1 + 8 * (a - b))**0.5 - 1) // 2 >= 0:
#         ans = ((1 + 8 * (a - b))**0.5 - 1) // 2
#         print(int(ans))
#     else:
#         n1 = int(((1 + 8 * (a - b))**0.5 - 1) // 2) + 1
#         while (n1 * (n1 + 1) // 2) % 2 != (a - b) % 2:
#             n1 += 1
#         print(n1)

# for t in range(int(input())):
#     n = int(input())
#     a = list(map(int, input().split()))
#     a.sort()
#     ans = 0
#     l = 0
#     dic = {}
#     for i in range(n - 1, -1, -1):
#         if not a[i] % 2:
#             l, r = 0, 30
#             while l < r:
#                 m = (l + r) // 2
#                 # print(l, r, m, a[i] % 2**m)
#                 if a[i] % 2**m:
#                     r = m
#                 else:
#                     l = m + 1
#             dic[a[i] // 2**(l - 1)] = max(dic.get(a[i] // 2**(l - 1), 0), l - 1)
#     print(sum(list(dic.values())))

# n = int(input())
# s = input()
# b = s.count('B')
# w = n - b
# if b % 2 and w % 2:
#     print(-1)
# elif not b or not w:
#     print(0)
# else:
#     ans = []
#     if not b % 2:
#         for i in range(n - 1):
#             if s[i] != 'W':
#                 ans += [str(i + 1)]
#                 s = s[:i] + 'W' + 'BW'[s[i + 1] == 'B'] + s[i + 2:]
#     elif not w % 2:
#         for i in range(n - 1):
#             if s[i] != 'B':
#                 ans += [str(i + 1)]
#                 s = s[:i] + 'B' + 'WB'[s[i + 1] == 'W'] + s[i + 2:]
#     print(len(ans))
#     print(' '.join(ans))

# n, m = list(map(int, input().split()))
# a = list(map(int, input().split()))
# b = list(map(int, input().split()))
# b.sort()
# ans = float('inf')
# for i in range(n):
#     x = (b[0] - a[i]) % m
#     ax = []
#     for j in range(n):
#         ax.append((a[j] + x) % m)
#     if b == sorted(ax):
#         ans = min(ans, x)
# print(ans)

# for t in range(int(input())):
#     n = int(input())
#     ans = [1] + [0] * (n - 1)
#     p = list(map(int, input().split()))
#     i, j, curr, m = p.index(1), 1, 1, 1
#     l, r = i, i
#     while l >= 0 and r < n:
#         if l and curr + p[l - 1] == (m + 2) * (m + 1) // 2:
#             ans[m] = 1
#             curr += p[l - 1]
#             l -= 1
#
#         elif r + 1 < n and curr + p[r + 1] == (m + 2) * (m + 1) // 2:
#             ans[m] = 1
#             curr += p[r + 1]
#             r += 1
#         else:
#             if l and r + 1 < n:
#                 curr, l, r = ((curr + p[l - 1], l - 1, r),
#                               (curr + p[r + 1], l, r + 1))[p[r + 1] < p[l - 1]]
#             elif not l and r + 1 < n:
#                 curr, l, r = curr + p[r + 1], l, r + 1
#             elif r + 1 == n and l:
#                 curr, l, r = curr + p[l - 1], l - 1, r
#             else:
#                 break
#         m += 1
#     print(''.join([str(i) for i in ans]))

# for t in range(int(input())):
#     n = int(input())
#     p = [input() for i in range(n)]
#     ans = 0
#     for i in range(n):
#         if p[i] in p[i + 1:]:
#             for j in range(10):
#                 code = p[i][:3] + str(j)
#                 if code not in p:
#                     p[i] = code
#                     ans += 1
#                     break
#     print(ans)
#     for code in p:
#         print(code)

# for t in range(int(input())):
#     a, b = list(map(int, input().split()))
#     if (a + b) % 3 == 0 and 2 * min(a, b) >= max(a, b):
#         print('YES')
#     else:
#         print('NO')

# for t in range(int(input())):
#     x, y = list(map(int, input().split()))
#     if (x == 1 and y > 1) or (x == 2 and y > 3) or (x == 3 and y > 3):
#         print('NO')
#     else:
#         print('YES')

# for t in range(int(input())):
#     n, m = list(map(int, input().split()))
#     a = list(map(int, input().split()))
#     if m < n or n == 2:
#         print(-1)
#     elif m == n:
#         print(2 * sum(a))
#         for i in range(n - 1):
#             print(i + 1, i + 2)
#         print(n, 1)
#     else:
#         b = [(a[i], i + 1) for i in range(n)]
#         b.sort()
#         d = m - n
#         ans = sum(a) + d * (b[0][0] + b[1][0])
#         for i in range(d):
#             print(b[0][1], b[1][1])
#         for i in range(n - 1):
#             print(i + 1, i + 2)
#         print(n, 1)

# n = int(input())
# a = list(map(int, input().split()))
# if n % 2:
#     print(-1)
# else:
#     d = 0
#     c = []
#     curr = 0
#     came = set()
#     day = set()
#     inc = False
#     for i in range(n):
#         if a[i] > 0:
#             if a[i] in day:
#                 inc = True
#                 break
#             else:
#                 day.add(a[i])
#                 came.add(a[i])
#         else:
#             if abs(a[i]) not in came:
#                 inc = True
#                 break
#             else:
#                 came.remove(abs(a[i]))
#         if len(came) == 0:
#             d += 1
#             c.append(i + 1)
#             day = set()
#     if len(came) > 0:
#         inc = True
#     if inc:
#         print(-1)
#     else:
#         print(d)
#         print(c[0])
#         for i in range(1, len(c)):
#             print(c[i] - c[i - 1])

# n = int(input())
# a = list(map(int, input().split()))
# a.sort()
# x, y = sum(a[:n // 2])**2, sum(a[n // 2:])**2
# print(x + y)

# for t in range(int(input())):
#     n = int(input())
#     r, p, s = list(map(int, input().split()))
#     b = input()
#     S, P, R = b.count('S'), b.count('P'), b.count('R')
#     cnt = 0
#     ans = ''
#     # print(r, 'rock', p, 'paper', s, 'sc')
#     for i in range(n):
#         if b[i] == 'S':
#             if r > 0:
#                 ans, r, cnt = ans + 'R', r - 1, cnt + 1
#             else:
#                 if p > R:
#                     ans, p = ans + 'P', p - 1
#                 if len(ans) < i + 1 and s > P:
#                     ans, s = ans + 'S', s - 1
#             S -= 1
#         elif b[i] == 'P':
#             if s > 0:
#                 ans, s, cnt = ans + 'S', s - 1, cnt + 1
#             else:
#                 if p > R:
#                     ans, p = ans + 'P', p - 1
#                 if len(ans) < i + 1 and r > S:
#                     ans, r = ans + 'R', r - 1
#             P -= 1
#         else:
#             if p > 0:
#                 ans, p, cnt = ans + 'P', p - 1, cnt + 1
#             else:
#                 if s > P:
#                     ans, s = ans + 'S', s - 1
#                 if len(ans) < i + 1 and r > S:
#                     ans, r = ans + 'R', r - 1
#             R -= 1
#     if cnt < (n // 2 + n % 2):
#         print('NO')
#     else:
#         print('YES')
#         # print(r, p, s)
#         print(ans)

# for t in range(int(input())):
#     n = int(input())
#     s = input()
#     f, l = s.find('1'), s.rfind('1')
#     f, l = max(f + 1, n - f) if f != -1 else 0, max(l + 1, n - l) if l != -1 else 0
#     if not f and not l:
#         print(n)
#     else:
#         print(f * 2) if f > l else print(l * 2)

# t = int(input())
# ans = list()
# for _ in [0] * t:
#     n, r = map(int, input().split())
#     x = sorted(set(map(int, input().split())))[::-1]
#     ans.append(sum([x - i * r > 0 for i, x in enumerate(x)]))
# print(' '.join(map(str, ans)))

# n = int(input())
# dots = []
# for i in range(n):
#     dots.append(sum(list(map(int, input().split()))))
# print(max(dots))

# n, m = map(int, input().split())
# print(pow(2**m - 1, n, 10**9 + 7))

# n, k = map(int, input().split())
# s = input()
# if not k:
#     print(s)
# elif n == 1:
#     print('0')
# else:
#     s = [int(i) for i in s]
#     if s[0] > 1:
#         s[0], k = 1, k - 1
#     for i in range(1, n):
#         if not k:
#             break
#         if s[i] > 0:
#             s[i], k = 0, k - 1
#     print(''.join(map(str, s))) if len(s) > 1 else print('0')

# m, n = map(int, input().split())
# r = list(map(int, input().split()))
# c = list(map(int, input().split()))
# grid = [['ok'] * (n + 1) for i in range(m + 1)]
#
# for i in range(m):
#     row = r[i]
#     if row:
#         for j in range(row):
#             grid[i][j] = 1
#         grid[i][row] = 0
#     else:
#         grid[i][row] = 0
#
#
# inv = False
# for j in range(n):
#     col = c[j]
#     if col:
#         for i in range(col):
#             if grid[i][j] == 0:
#                 inv = True
#                 break
#             else:
#                 grid[i][j] = 1
#         if grid[col][j] == 1:
#             inv = True
#             break
#         else:
#             grid[col][j] = 0
#     else:
#         if grid[col][j] == 1:
#             inv = True
#             break
#         else:
#             grid[col][j] = 0
#
# if inv:
#     print(0)
# else:
#     cnt = 0
#     for row in grid[:m]:
#         cnt += row[:n].count('ok')
#     print(pow(2, cnt, 10**9 + 7))

# n = int(input())
# for i in range(n):
#     print('BW' * (n // 2) + 'B' * (n % 2) if i % 2 else 'WB' * (n // 2) + 'W' * (n % 2))

# n = int(input())
# a = list(map(int, input().split()))
# curr, odd, even = 0, 0, 0
# p = 0
# for d in a:
#     odd, even = ((odd, even + 1), (odd + 1, even))[curr % 2]
#     curr += 1 if d < 0 else 0
#     p += odd if curr % 2 else even
# print(n * (n + 1) // 2 - p, p)

# n = int(input())
# a = list(map(int, input().split()))
# p, m, z = 0, [], 0
# for d in a:
#     if d > 0:
#         p += d
#     elif d < 0:
#         m.append(d)
#     else:
#         z += 1
# ans = p - (n - z - len(m))
#
# if len(m) % 2:
#     if z:
#         m.append(-1)
#         ans += 1
#         z -= 1
#     else:
#         m.sort(reverse=True)
#         x = m.pop()
#         ans += 1 - x
#
# mm = len(m)
# ans += abs(sum(m)) - mm
# ans += z
# print(ans)

# n, l, r = map(int, input().split())
# a = [2**i for i in range(r)]
# print(sum(a[:l]) + n - l, sum(a) + (n - r) * a[-1])

# n = int(input())
# a = list(map(int, input().split()))
# a.sort()
# print('YES' if not sum(a) % 2 and a[-1] <= sum(a) - a[-1] else 'NO')

# for t in range(int(input())):
#     n, m, k = map(int, input().split())
#     h = list(map(int, input().split()))
#     ans = 'YES'
#     for i in range(n - 1):
#         if abs(h[i] - h[i + 1]) > k:
#             d = h[i] - h[i + 1]
#             if d < 0 and m >= abs(d) - k:
#                 m -= -k - d
#             elif d > 0:
#                 m += min(d + k, h[i])
#             else:
#                 ans = 'NO'
#                 break
#         else:
#             d = h[i] - h[i + 1]
#             if d >= 0:
#                 m += min(d + k, h[i])
#             else:
#                 m += min(k + d, h[i])
#     print(ans)

# h, l = map(int, input().split())
# print((h**2 + l**2) / (2 * h) - h)

# n = int(input())
# a = list(map(int, input().split()))
# a = {i: j for i, j in enumerate(a)}
# m, idx = 0, 0
# ans = 'YES'
# for i in range(n):
#     if a[i] > m:
#         m = a[i]
#         idx = i
# for i in range(1, idx):
#     if a[i] < a[i - 1]:
#         ans = 'NO'
#         break
# for i in range(idx + 1, n):
#     if a[i] > a[i - 1]:
#         ans = 'NO'
#         break
# print(ans)

# n, k = map(int, input().split())
# l, r = 0, n
# while l <= r:
#     m = (l + r) // 2
#     t = n - m
#     if m * (m + 1) // 2 - t == k:
#         ans = t
#         break
#     elif m * (m + 1) // 2 - t < k:
#         l = m + 1
#     else:
#         r = m - 1
# print(ans)

# for t in range(int(input())):
#     n, m = map(int, input().split())
#     grid = [input() for i in range(n)]
#     rows = []
#     cols = [0] * m
#     for row in grid:
#         rows.append(0)
#         for i in range(m):
#             if row[i] == '.':
#                 rows[-1] += 1
#                 cols[i] += 1
#     ans = m + n - 1
#     for i in range(n):
#         for j in range(m):
#             ans = min(ans, rows[i] + cols[j] - (grid[i][j] == '.'))
#     print(ans)

tiles = input().split()
unique = {}
m, p, s = set(), set(), set()
m_unique = 0
for t in tiles:
    unique[t] = unique.get(t, 0) + 1
    m_unique = max(m_unique, unique[t])
    if t[1] == 'm':
        m.add(int(t[0]))
    elif t[1] == 'p':
        p.add(int(t[0]))
    else:
        s.add(int(t[0]))
ans = 3 - m_unique
for t in (m, p, s):
    if not t:
        continue
    else:
        m_sub = 0
        l = list(sorted(t))
        dif = []
        for i in range(1, len(t)):
            dif.append(l[i] - l[i - 1])
            if dif[-1] == 1 or dif[-1] == 2:
                m_sub = max(m_sub, 2)
            if i > 1 and dif[-1] == dif[-2] == 1:
                m_sub = 3
            # print(l, dif, m_sub)
    ans = min(ans, 3 - m_sub)
print(ans)

strings = list(map(str, input().split()))
s1, s2, s3 = strings[0], strings[1], strings[2]

check = {'m': [], 'p': [], 's': []}

check[s1[1]].append(int(s1[0]))
check[s2[1]].append(int(s2[0]))
check[s3[1]].append(int(s3[0]))
check['m'].sort()
check['p'].sort()
check['s'].sort()

cm, cp, cs = len(check['m']), len(check['p']), len(check['s'])

if cm == cp == cs == 1:
    print(2)
else:
    ans = 0
    diff = list()

    if cm > cp and cm > cs:
        for i in range(cm-1):
            diff.append(abs(check['m'][i] - check['m'][i + 1]))
    elif cp > cm and cp > cs:
        for i in range(cp-1):
            diff.append(abs(check['p'][i] - check['p'][i + 1]))
    else:
        for i in range(cs-1):
            diff.append(abs(check['s'][i] - check['s'][i + 1]))

    if len(diff) == 1:
        if diff[0] == 0 or diff[0] == 1 or diff[0] == 2:
            ans = 1
        else:
            ans = 2
    elif len(diff) == 2:
        if diff[0] == diff[1]:
            if diff[0] == 2:
                ans = 1
            elif diff[0] > 2:
                ans = 2
        elif diff[0] != diff[1]:
            for i in diff:
                if i == 0 or i == 1 or i == 2:
                    ans = 1
                    break
            else:
                ans = 2

    print(ans)

d = {
        'm': 10,
        's': 30,
        'p': 60
}

a, b, c = list(sorted([int(i[0]) + d[i[1]] for i in input().split(' ')]))

if (a == b and b == c) or (a == b - 1 and b == c - 1):
    print(0)
elif a == b - 1 or b == c - 1 or a == b or b == c or a == c - 2 or a == b - 2 or b == c - 2:
    print(1)
else:
    print(2)

'''
d={'m':10,'p':30,'s':50}

#men=> kou or shu
a,y,z=sorted([int(x[0])+d[x[1]] for x in (input().split())])
print(a,y,z)
#kou and sust
if (a==y and y==z) or (a==y-1 and y==z-1):
    print(0)
elif a==y or y==z or a==z or a==y-1 or y==z-1 or a==y-2 or y==z-2 :
    print(1)
else:
    print(2)
'''

d = {
        'm': 10,
        's': 30,
        'p': 60
}

a, b, c = list(sorted([int(i[0]) + d[i[1]] for i in input().split(' ')]))

if (a == b and b == c) or (a == b - 1 and b == c - 1):
    print(0)
    exit()
if a == b - 1 or b == c - 1 or a == b or b == c or a == c - 2 or a == b - 2 or b == c - 2:
    print(1)
    exit()
print(2)

'''
d={'m':10,'p':30,'s':50}

#men=> kou or shu
a,y,z=sorted([int(x[0])+d[x[1]] for x in (input().split())])
print(a,y,z)
#kou and sust
if (a==y and y==z) or (a==y-1 and y==z-1):
    print(0)
elif a==y or y==z or a==z or a==y-1 or y==z-1 or a==y-2 or y==z-2 :
    print(1)
else:
    print(2)
'''

def main():
    s = input().split()

    maxIdent = 0
    maxIncr = 0

    for el in s:
        cnt = s.count(el)
        if cnt == 3:
            print(0)
            return
        if cnt > maxIdent:
            maxIdent = cnt

        cnt2 = 1
        item1 = str(int(el[0]) + 1) + el[1]
        item2 = str(int(el[0]) + 2) + el[1]
        if item1 in s or item2 in s:
            cnt2 = 2
            if item1 in s and item2 in s:
                print(0)
                return
        if cnt2 > maxIncr:
            maxIncr = cnt2

    maxIdent = 3 - maxIdent
    maxIncr = 3 - maxIncr
    print(min([maxIdent, maxIncr]))

main()

first_list = raw_input().split()
data_dic = {}
for item in first_list:
    digit = int(item[0])
    letter = item[1]
    if letter not in data_dic:
        data_dic.update({letter: [digit]})
    else:
        data_dic[letter].append(digit)
koutsu = False
shuntsu = False
koutsu_action = 100
shuntsu_action = 100
for j in data_dic:
    for i in data_dic[j]:
        if data_dic[j].count(i) >= 3:
            koutsu = True
        else:
            koutsu_action = min(koutsu_action, 3 - data_dic[j].count(i))
        if i + 1 in data_dic[j] and i - 1 in data_dic[j]:
            shuntsu = True
        elif i + 1 in data_dic[j] or i - 1 in data_dic[j]:
            shuntsu_action = min(shuntsu_action, 1)
        elif i - 2 in data_dic[j] or i + 2 in data_dic[j]:
            shuntsu_action = min(shuntsu_action, 1)
        else:
            shuntsu_action = min(shuntsu_action, 2)
if shuntsu or koutsu:
    print(0)
else:
    print(min(shuntsu_action, koutsu_action))

import sys

a,b,c=map(str,raw_input().split())
d={}
h={}
l=[a,b,c]

for i in xrange(len(l)):
    key=l[i][1]
    if key not in d:
        d[key]=[int(l[i][0])]
    else:
        d[key].append(int(l[i][0]))

q=d.values()

ans=2
for i in xrange(len(q)):
    u=q[i]
    if len(u)==1:
        ans=min(ans,2)
    elif len(u)==2:
        if len(set(u))==1:
            ans=min(1,ans)
        elif abs(u[0]-u[1])==1:
            ans=min(ans,1)
        elif abs(u[0]-u[1])==2:
            ans=min(ans,1)
        else:
            ans=min(ans,2)
    elif len(u)==3:
        u.sort()
        if len(set(u))==1:
            print 0
            sys.exit()
        elif u[1]-u[0]==1 and u[2]-u[1]==1:
            print 0
            sys.exit()
        elif u[1]-u[0]<=1 or u[1]-u[0]<=2:
            ans=min(1,ans)
        elif u[2]-u[1]<=1 or u[2]-u[1]<=2:
            ans=min(1,ans)
        elif u[2]-u[0]<=2:
            ans=min(1,ans)
        else:
            ans=min(2,ans)
print ans

l=[x for x in input().split()]
m=[0]*10
p=[0]*10
s=[0]*10
for i in range(len(l)):
        if l[i][1]=="m":
                m[int(l[i][0])]+=1
        elif l[i][1]=="p":
                p[int(l[i][0])]+=1
        else:
                s[int(l[i][0])]+=1
flag1=1
flag2=1
flag3=1
flag4=1
flag5=1
for i in range(10):
        if m[i]>=3 or p[i]>=3 or s[i]>=3:
                print(0)
                flag1=0
                flag2=0
                flag3=0
                flag4=0
                flag5=0
                break
if flag3:
        for i in range(8):
                if m[i]>=1 and m[i+1]>=1 and m[i+2]>=1 or p[i]>=1 and p[i+1]>=1 and p[i+2]>=1 or s[i]>=1 and s[i+1]>=1 and s[i+2]>=1:
                        print(0)
                        flag1=0
                        flag2=0
                        flag4=0
                        flag5=0
                        break

if flag1:
        for i in range(9):
                if m[i]>=1 and m[i+1]>=1 or p[i]>=1 and p[i+1]>=1 or s[i]>=1 and s[i+1]>=1:
                        print(1)
                        flag2=0
                        flag4=0
                        flag5=0
                        break

if flag4:
        for i in range(10):
                if m[i]==2 or p[i]==2 or s[i]==2:
                        print(1)
                        flag2=0
                        flag5=0
                        break

if flag5:
        for i in range(8):
                if m[i]>=1 and m[i+2]>=1 or p[i]>=1 and p[i+2]>=1 or s[i]>=1 and s[i+2]>=1:
                        print(1)
                        flag2=0
                        break

if flag2:
        if len(l)>=1:
                print(2)
        else:
                print(3)

a=map(str,raw_input().split())
m=[0 for i in range(9)]
p=[0 for i in range(9)]
s=[0 for i in range(9)]
for i in a:
    if i[1]=='m':
        m[int(i[0])-1]+=1
    elif i[1]=="p":
        p[int(i[0])-1]+=1
    else:
        s[int(i[0])-1]+=1
ans=2
con=0
con1=0
k=0
for i in m:
    k+=1
    if i==3:
        ans=0
        break
    if i==2:
        ans=min(ans,1)
        break
    if i==1:
        con+=1
        ans=min(ans,2)
        if k<8:
            if m[k]==0:
                if m[k+1]!=0:
                    con1=max(con1,2)
    if i==0:
        con1=max(con,con1)
        con=0

con1=max(con,con1)
con=0
k=0
for i in p:
    k+=1
    if i==3:
        ans=0
        break
    if i==2:
        ans=min(ans,1)
        break
    if i==1:
        ans=min(ans,2)
        con+=1
        if k<8:
            if p[k]==0:
                if p[k+1]!=0:
                    con1=max(con1,2)
    if i==0:
        con1=max(con,con1)
        con=0

con1=max(con,con1)
con=0
k=0
for i in s:
    k+=1
    if i==3:
        ans=0
        break
    if i==2:
        ans=min(ans,1)
        break
    if i==1:
        ans=min(ans,2)
        con+=1
        if k<8:
            if s[k]==0:
                if s[k+1]!=0:
                    con1=max(con1,2)
    if i==0:
        con1=max(con,con1)
        con=0

con1=max(con,con1)
con=0
print min(ans,3-con1)

a, b, c = input().split()
tiles = set()
for i in a, b, c:
    tiles.add(i)
if len(tiles) == 1:
    print(0)
elif len(tiles) == 2:
    print(1)
else:
    pairs = []
    for i in a, b, c:
        num = i[:-1]
        let = i[-1]
        pairs.append((int(num), let))
    pairs = sorted(pairs)
    if pairs[0][1] == pairs[1][1] and pairs[1][1] == pairs[2][1]:
        if pairs[0][0] == pairs[1][0] - 1 and pairs[1][0] == pairs[2][0] - 1:
            print(0)
        elif pairs[0][0] == pairs[1][0] - 1 or pairs[1][0] == pairs[2][0] - 1 or pairs[0][0] == pairs[1][0] - 2 or pairs[1][0] == pairs[2][0] - 2:
            print(1)
        else:
            print(2)
    else:
        matches = [0, 0]
        if pairs[0][1] == pairs[1][1]:
            matches = [pairs[0][0], pairs[1][0]]
        elif pairs[1][1] == pairs[2][1]:
            matches = [pairs[1][0], pairs[2][0]]
        elif pairs[0][1] == pairs[2][1]:
            matches = [pairs[0][0], pairs[2][0]]
        if matches[0] == matches[1] - 1 or matches[0] == matches[1] - 2:
            print(1)
        else:
            print(2)

from collections import Counter

X, Temp = input()[::-1].split(), 1
MyDict = Counter(X)
if 3 in MyDict.values():
    print(0)
    exit()
Key = sorted(MyDict.keys())
Max = max(MyDict.values())
for i in range(1, len(Key)):
    Diff = int(Key[i][1]) - int(Key[i - 1][1])
    if Key[i][0] == Key[i - 1][0] and Diff <=2 :
        if Diff == 2:
            print(1)
            exit()
        Temp += 1
    else:
        Temp = 1
    Max = max(Max, Temp)
print(max(0, 3 - Max))

# Show you deserve being the best to whom doesn't believe in you.

# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(str, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

t = readl()
n = []
m = []
t.sort()
for i in t:
    n.append(int(i[0]))
    m.append(i[1])
count = 2
if m[0] == m[1] == m[2]:
    if n[0] == n[1] == n[2] or (n[0] + 1 == n[1] and n[1] + 1 == n[2]):
        print(0)
    elif n[0] == n[1] or n[0] == n[2] or n[1] == n[2]:
        print(1)
    elif n[0] + 1 == n[1] or n[0] + 2 == n[1] or n[1] + 1 == n[2] or n[1] + 2 == n[2] or n[0] + 1 == n[2] or n[0] + 2 == n[2]:
        print(1)
    else:
        print(2)
elif m[0] == m[1]:
    if n[0] == n[1] or n[0] + 1 == n[1] or n[0] + 2 == n[1]:
        print(1)
    else:
        print(2)
elif m[0] == m[2]:
    if n[0] == n[2] or n[0] + 1 == n[2] or n[0] + 2 == n[2]:
        print(1)
    else:
        print(2)
elif m[1] == m[2]:
    if n[1] == n[2] or n[1] + 1 == n[2] or n[1] + 2 == n[2]:
        print(1)
    else:
        print(2)
else:
    print(2)

M = 10**9 + 7
R = lambda: map(int, input().split())
L = [[0 for j in range(9)] for i in range(3)]
#print(L)
a = input().split()
def f(p):
    if p[1] == 'm':
        L[0][int(p[0])-1] += 1
    elif p[1] == 'p':
        L[1][int(p[0])-1] += 1
    elif p[1] == 's':
        L[2][int(p[0])-1] += 1
for i in range(3):
    f(a[i])
p = sum(L[0])
q = sum(L[1])
r = sum(L[2])
m = max([p,q,r])
#print(L)
'''if m == 1:
    print(2)
elif m == 2:
    for i in range(3):
        for j in range(8):
            if L[i][j] == 1 and L[i][j+1] == 1:
                print(1)
                quit()
    print(2)
elif m == 3:'''
if len(set(a)) == 1:
    print(0)
    quit()
elif len(set(a)) == 2:
    print(1)
    quit()
k = 0
for i in range(3):
    for j in range(7):
        k = max(k,L[i][j]+L[i][j+1]+L[i][j+2])
    k = max(k,L[i][7]+L[i][8])
if k == 3:
    print(0)
elif k == 2:
    print(1)
elif k == 1:
    print(2)

a=list(input().split())
ar1=[]
ar2=[]
for i in a:
    ar1.append(int(i[0]))
    ar2.append(i[1])
s=set()
for i in range(3):
    for j in range(i+1,3):
        if ar2[i]==ar2[j]:
            s.add(i)
            s.add(j)
if len(s)==0:
    print(2)
elif len(s)==2:
    i1=s.pop()
    i2=s.pop()
    if abs(ar1[i1]-ar1[i2])<=2:
        print(1)
    else:
        print(2)
else:
    ar1.sort()
    d1=ar1[1]-ar1[0]
    d2=ar1[2]-ar1[1]
    if d1==0:
        if d2==0:
            print(0)
        else:
            print(1)
    elif d1==1:
        if d2==1:
            print(0)
        else:
            print(1)
    elif d1==2 or d2==2:
        print(1)
    else:
        if d2==0 or d2==1:
            print(1)
        else:
            print(2)

cards = input().split()
ans = 2
if cards[0] == cards[1] and cards[2] == cards[1]:
    ans = 0
elif cards[0] == cards[1] or cards[0] == cards[2] or cards[2] == cards[1]:
    ans = 1
else:
    if cards[0][1] == cards[1][1] and cards[0][1] == cards[2][1]:
        if abs(int(cards[0][0]) - int(cards[1][0])) <= 2 and abs(int(cards[0][0]) - int(cards[2][0])) <= 2 and abs(int(cards[1][0]) - int(cards[2][0])) <= 2:
            ans = 0
        elif abs(int(cards[0][0]) - int(cards[1][0])) <= 2 or abs(int(cards[0][0]) - int(cards[2][0])) <= 2 or abs(int(cards[1][0]) - int(cards[2][0])) <= 2:
            ans = 1
    elif not(cards[0][1] != cards[1][1] and cards[0][1] != cards[2][1] and cards[2][1] != cards[1][1]):
        if cards[0][1] == cards[1][1]:
            card1, card2 = cards[0], cards[1]
        elif cards[0][1] == cards[2][1]:
            card1, card2 = cards[0], cards[2]
        else:
            card1, card2 = cards[1], cards[2]
        if abs(int(card1[0]) - int(card2[0])) <= 2:
            ans = 1
print(ans)

#include<bits/stdc++.h>
#include<stdio.h> //per fare input output con scanf and printf
#include<stdlib.h> //per fare qsort e bsearch
#include<string.h> // per fare strcpy(sarrivo, spartenza) strcat(str, aggiungo) strcmp(a,b) che da 0 se sono uguali
#include<math.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<map>

#using namespace std;

#define ld long double
#define ll long long int
#define vi vector <ll>
#define pi pair <ll, ll>
#define binary(v, el) binary_search((v).begin(), (v).end(), (el))
#define PB push_back
#define MP make_pair
#define F first
#define S second

x,y,z = list(map(str, input().strip().split()))

def cazzu(a,b,c):
    if a==b==c:
        return 1
    else:
        return 0

def shizu(a,b,c):
    x = int(a[0])
    y = int(b[0])
    z = int(c[0])
    l = [x,y,z]
    l.sort()
    if a[1]==b[1]==c[1] and l[1]-l[0] == 1 and l[2]-l[1]==1:
        return 1
    else:
        return 0

if cazzu(x,y,z) or shizu(x,y,z):
    print(0)
else:
    flag = 0
    for i in ['p','m','s']:
        for j in ['1','2','3','4','5','6','7','8','9']:
            w = j+i
            if cazzu(x,y,w) or shizu(x,y,w) or cazzu(x,w,z) or shizu(x,w,z) or cazzu(w,y,z) or shizu(w,y,z):
                flag = 1

    if flag == 1:
        print(1)
    else:
        print(2)

def meth(arr):
    for i in range(3):
        arr[i]=int(arr[i])
    arr.sort()
    if arr[0]+1==arr[1] and arr[0]+2==arr[2]:
        return 0
    if arr[1]-arr[0]>=3 and arr[2]-arr[1]>=3:
        return 2
    return 1

def meth1(arr):
    for i in range(2):
        arr[i]=int(arr[i])
    arr.sort()
    if arr[0]+1==arr[1] or arr[0]+2==arr[1] or arr[0]==arr[1]:
        return 1

    return 2

a,b,c=input().split()
if a==b==c:
    print(0)
    exit(0)
if a[1]==b[1]==c[1]:
    print(meth([a[0],b[0],c[0]]))
    exit(0)

if a[1]==b[1] and b[1]!=c[1]:
    print(meth1([a[0],b[0]]))
    exit(0)

if c[1]==b[1] and a[1]!=c[1]:
    print(meth1([b[0],c[0]]))
    exit(0)

if a[1]==c[1] and b[1]!=c[1]:
    print(meth1([a[0],c[0]]))
    exit(0)

print(2)
exit(0)

"""
from sys import stdin,stdout
n,m,k=list(map(int,stdin.readline().split()))

def m1(x,k):
    if x%k==0:
        return x//k
    return x//k+1

def meth(arr):
    if arr==[]:
        return []
    a=[]
    #a=[[] for _ in range(m1(arr[-1],k))  ]
    tmp=[]
    for x in arr:
        if m1(x,k)-1==0:
            tmp.append(x)
        else:
            a.append(x)
    a=[tmp]+a
    if [] in a:
        a.remove([])
    return a

a=list(map(int,stdin.readline().split()))

arr=meth(a)
res=0
while len(arr)>1:
    #print(arr)
    val=arr.pop(0)
    if isinstance(val,int):
        break
    ln=len(val)
    newarr=[]

    for i in range(len(arr)):
        arr[i]-=ln

    arr=meth(arr)
    res+=1

stdout.write(str(res+1)+"\n")

"""

def main():
    list_str = input().split()
    list_str.sort()

    """ p = ['3p', '5s', '5s'] (after sort)
    sorted by decimal its mean either ['3p','5p'] or ['5p','5p']
    near to koutsu, or whole string koutsu
    either 1,2,3.... 0 is impossible"""
    # if koutsu 2 or 3 then cannot be shuntsu
    koutsu_count = 1
    if list_str[0] == list_str[1] and list_str[1] == list_str[2]:  # all equal
        koutsu_count = 3
        print('0')
        return # if koutsu 2 or 3 then cannot be shuntsu

    elif list_str[0] == list_str[1] or list_str[1] == list_str[2]:  # either one equal
        koutsu_count = 2
        print('1')
        return # if koutsu 2 or 3 then cannot be shuntsu

    ###############################################
    shuntsu_count = 0
    """
    1s,5m,3s  => after sort 1s,3s,5m
    1s,5m,2s  => after sort 1s,2s,5m
    1s,2m,2s  => after sort 1s,2m,2s

    so i guess better to digits

    1,2,2
    s,m,s
    """
    num = []
    lstr = []
    for e in list_str:
        num.append(int(e[0]))
        lstr.append(e[1])

    # sorted so smallest to largest

    if lstr[0] == lstr[1] and (num[0] == num[1]-1 or num[0] == num[1]-2):
        shuntsu_count += 1

    if lstr[0] == lstr[2] and (num[0] == num[2]-1 or num[0] == num[2]-2):
        shuntsu_count += 1

    if lstr[1] == lstr[2] and (num[1] == num[2]-1 or num[1] == num[2]-2):
        shuntsu_count += 1

    if shuntsu_count >= 3:
        print('0')
    elif shuntsu_count == 0:
        # atleast Count one of kind already
        print('2')
    else:
        print('1')

main()

p = input().split()
p = set(p)
ans = 2
lol = [0] * 3
for i1 in p:
    for i2 in p:
        if i1[1] == i2[1] and 1 <= int(i1[0]) - int(i2[0]) <= 2:
            if int(i1[0]) - int(i2[0]) == 1:
                lol[1] += 1
            else:
                lol[2] = 1
ans -= max(lol)
ans = min(ans, len(p) - 1)
print(max(0, ans))

m=[x for x in input().split()]
tiles=[[0 for i in range(9)] for j in range(3)]
for i in range(len(m)):
    g=int(m[i][0])-1
    h=(m[i][1])
    if h=="m":
        tiles[0][g]+=1
    elif h=="p":
        tiles[1][g]+=1
    else:
        tiles[2][g]+=1
if m[0]==m[1] and m[1]==m[2]:
    print(0)
elif m[0]==m[1]:
    print(1)
elif m[0]==m[2]:
    print(1)
elif m[1]==m[2]:
    print(1)
else:
    n=False
    for i in range(3):
        for j in range(9):
            if tiles[i][j]!=0:
                if j!=8 and tiles[i][j+1]!=0:
                    if j!=7 and tiles[i][j+2]!=0:
                        print(0)
                        n=True
                        break
                    else:
                        print(1)
                        n=True
                        break
                elif j!=7 and j!=8 and tiles[i][j+2]!=0:
                    print(1)
                    n=True
                    break
    if n==False:
        print(2)

x, y, z = map(str, input().split())
s = set()

s.add(x)
s.add(y)
s.add(z)

f = 3
if len(s)==1:
    print(0)
else:
    if len(s)==2:
        print(1)
    else:
        z = 0
        for t in s:
            d = s.copy()
            if int(t[0])<=7:
                d.add(f"{int(t[0])+1}{t[1]}")
                d.add(f"{int(t[0])+2}{t[1]}")
            else:
                d.add("dfdsf")
                d.add("dfdf")
            a = s.copy()
            if 1<=int(t[0])<=8:
                a.add(f"{int(t[0])-1}{t[1]}")
                a.add(f"{int(t[0])+1}{t[1]}")
            else:
                a.add("dfdsf")
                a.add("dfdf")
            b = s.copy()
            if int(t[0])>=2:
                b.add(f"{int(t[0])-1}{t[1]}")
                b.add(f"{int(t[0])-2}{t[1]}")
            else:
                b.add("dfdsf")
                b.add("dfdf")
            #print(d, b, a)
            if z:
                f = min(f, len(d), len(a), len(b))
            else:
                f = min(len(d), len(a), len(b))
            z+=1
        if f-3<0:
            print(0)
        else:
            print(f-3)

n=list(map(str,input().split(" ")))

d=dict()

mp = {"m":0 , "p":1 , "s":2}

l=[0]*10
ll=[0]*10
lll=[0]*10
arr = [l,ll,lll]

maxi=0

for i in n:
	# print(i)
	if (i in d.keys()):
		d[i]+=1
		maxi = max(maxi,d[i])

	else:
		d[i]=1
		maxi = max(maxi,d[i])

	arr[mp[i[1]]][int(i[0])-1] = 1

# print(arr)
# print(d)
if(maxi>=3):
	print(0)
else:
	temp2 = 0

	for i in range(3):
		ansi=0
		prev2=arr[i][0]
		prev1=arr[i][1]
		for j in range(10):
			if(j>=2 and prev2==1 and prev1==0 and arr[i][j]==1):
				temp2=max(temp2,2)
			if(arr[i][j] ==0):
				ansi=0
			if(arr[i][j]==1):
				ansi+=arr[i][j]
				temp2=max(ansi,temp2)
			prev2=prev1
			prev1=arr[i][j]

	finalAns = min(3-maxi, 3-temp2)
	print(finalAns)

b=list(input().split())
a=b[0]
c=b[1]
d=b[2]
p=[int(a[0]),int(c[0]),int(d[0])]
p.sort()
if a[1]==c[1]:
    if a[1]==d[1]:
        k=p[1]-p[0]
        q=p[2]-p[1]
        if k==0 and q==0:
            print(0)
        elif k==0 or q==0:
            print(1)
        elif k==1 and q==1:
            print(0)
        elif k==1 or q==1:
            print(1)
        elif k==2 or q==2:
            print(1)
        else:
            print(2)
    else:
        if int(a[0])==int(c[0]):
            print(1)
        elif abs(int(a[0])-int(c[0]))<=2:
            print(1)
        else:
            print(2)
else:
    if c[1]==d[1]:
        if int(c[0]) == int(d[0]):
            print(1)
        elif abs(int(c[0]) - int(d[0]))<= 2:
            print(1)
        else:
            print(2)
    elif a[1]==d[1]:
        if int(a[0]) == int(d[0]):
            print(1)
        elif abs(int(a[0]) - int(d[0]))<= 2:
            print(1)
        else:
            print(2)
    else:
        print(2)

a,b,c=sorted(6*ord(y)+int(x)for x,y in input().split())
s={b-a,c-b}
print(2-bool(s&{0,1,2})-(s<{0,1}))

a=list(map(str,input().split()));l=a
s=m=p=0;s1,m1,p1=[],[],[]
for i in a:
    if 's' in i:s+=1;s1+=[int(i[0])]
    elif 'p' in i:p+=1;p1+=[int(i[0])]
    else:m+=1;m1+=[int(i[0])]
if m and s and p:print(2)
elif len(set(a))==1:print(0)
elif max(s,m,p)==3:
    if s==3:a=s1
    elif m==3:a=m1
    else:a=p1
    a=sorted(a);r=2
    if a[1]-a[0]==a[2]-a[1]==1:r=0
    elif a[1]-a[0] in [1,2] or a[2]-a[1] in [1,2]:r=1
    else:r=2
    if len(set(l))==2:r=min(r,1)
    print(r)
else:
        if s==2:a=s1
        elif p==2:a=p1
        else:a=m1
        a=sorted(a)
        if a[1]-a[0]==1 or a[1]-a[0]==2:print(1)
        else:
            if len(set(l))==2:print(1)
            else:print(2)

# your code goes here
tiles = input().split(' ')
tiles.sort()
ans = 2
sq = 0

if (tiles[0] == tiles[1] and tiles[1] == tiles[2]):
	ans = 0
elif (tiles[0] != tiles[1] and tiles[1] != tiles[2]):
	if(tiles[0][1] == tiles[1][1]):
		if(int(tiles[0][0]) >= int(tiles[1][0]) - 2):
			ans = 1
			if(int(tiles[0][0]) == int(tiles[1][0]) - 1):
				sq = 1

	if(tiles[1][1] == tiles[2][1]):
		if(int(tiles[1][0]) == int(tiles[2][0]) - 1):
			ans = 1
			if(sq):
				ans = 0
		if(int(tiles[1][0]) == int(tiles[2][0]) - 2):
			ans = 1

	if(tiles[0][1] == tiles[2][1]):
		if(int(tiles[0][0]) >= int(tiles[2][0]) - 2 and sq != 1):
			ans = 1
else:
	ans = 1

print(ans)

a = input().split()
res = 2
for i in range(1, 10):
    for j in "smp":
        res = min(res, 3 - (str(i) + j in a) -
                  (str(i + 1) + j in a) - (str(i + 2) + j in a))
        res = min(res, 3 - a.count(str(i) + j))

print(res)

a = input().split()
a.sort()
if len(set(a)) == 1:
    print(0)
elif len(set(a)) == 2:
    print(1)
else:
    d = {}
    for i in a:
        n = int(i[0])
        c = i[1]
        if c in d:
            d[c].append(n)
        else:
            d[c] = [n]

    v = list(d.values())
    cond0 = False
    cond1 = False
    # print (d,v)
    for i in v:
        if len(i) == 2:
            i = sorted(i)
            x = i[0]
            y = i[1]
            if x + 1 == y or y - x == 2:
                cond1 = True
        if len(i) == 3:
            i = sorted(i)
            x = i[0]
            y = i[1]
            z = i[2]
            if x + 1 == y and y + 1 == z:
                cond0 = True

            if (x+1 == y) or (x+2 == y) or  (y+2 ==z) or (y+1 ==z):
                cond1 = True

    if cond0:
        print(0)
    elif cond1:
        print(1)
    else:
        print(2)

import collections

nums = list(map(str,input().split()))

dd = collections.defaultdict(int)

for i in nums:
 	dd[i] += 1

 	if dd[i] == 3:
 		print(0)
 		exit()

for key in dd:
 	if dd[key] == 2:
 		print(1)
 		exit()

 	else:
 		tk0 = str(int(key[0]) + 1) + key[1]
 		tk1 = str(int(key[0]) + 2) + key[1]
 		tk2 = str(int(key[0]) - 1) + key[1]
 		tk3 = str(int(key[0]) - 2) + key[1]

 		if tk1 in dd and tk0 in dd:
 			print(0)
 			exit()
 		elif tk0 in dd and tk2 in dd:
 			print(0)
 			exit()

 		elif tk2 in dd and tk3 in dd:
 			print(0)
 			exit()

 		elif tk0 in dd or tk1 in dd or tk2 in dd or tk3 in dd:
 			print(1)
 			exit()

print(2)
exit()

def same(nums):
    curr = nums[0]
    for i in nums:
        if i != curr:
            return False

    return True

def increasing(nums):
    for i in range(1,len(nums)):
        if nums[i]-nums[i-1] != 1:
            return False

    return True

def main():
    cards = list(map(str,input().split()))
    letters = {}
    #print(cards)
    for i in cards:
        if i[1] not in letters.keys():
            letters[i[1]] = [int(i[0])]
        else:
            letters[i[1]].append(int(i[0]))

    for i in letters.keys():
        letters[i].sort()

    if len(letters) == 1:
        for i in letters.keys():
            if same(letters[i]):
                print(0)
                return
            if increasing(letters[i]):
                print(0)
                return

            if (letters[i][0] == letters[i][1]) or (letters[i][1] == letters[i][2]):
                print(1)
                return
            diff1 = letters[i][1]-letters[i][0]
            diff2 = letters[i][2]-letters[i][1]
            if diff1 == 1 or diff2 == 1 or diff1 == 2 or diff2 == 2:
                print(1)
                return
            print(2)

    elif len(letters) == 2:
        for i in letters.keys():
            if len(letters[i]) == 2:
                if letters[i][0] == letters[i][1]:
                    print(1)
                    return
                diff1 = letters[i][1]-letters[i][0]
                if diff1 == 1 or diff1 == 2:
                    print(1)
                    return
                print(2)

    else:
        print(2)

main()

def for_k(l):
    if not l:
        return 3
    d = []
    for e in l:
        d.append(l.count(e))
    return max(3 - max(d), 0)

def for_s(l):
    t = [0 for _ in range(9)]
    if not l:
        return 3
    numbas = []
    for e in l:
        if e not in numbas:
            numbas.append(int(e[0]))

    if any([numbas[i] + 1 == numbas[i + 1] and numbas[i + 2] == numbas[i + 1] + 1 for i in range(len(numbas) - 2)]):
        return 0
    elif any([numbas[i] + 1 == numbas[i + 1] for i in range(len(numbas) - 1)]):
        return 1
    else:
        for n in numbas:
            t[n - 1] = 1

        gaps = []
        buff = 0
        for i in range(t.index(1), len(t)):
            if t[i] == 0:
                buff += 1
            else:
                if buff:
                    gaps.append(buff)
                    buff = 0

        if not gaps:
            return 2

        if min(gaps) >= 2:
            return 2
        elif min(gaps) == 1:
            return 1

a = input().split()

a.sort(key=lambda x: (x[1], x[0]))

x = []
y = []
z = []

for e in a:
    if e[1] == 'm':
        x.append(e)
    elif e[1] == 'p':
        y.append(e)
    else:
        z.append(e)

hello = []
for thing in (x, y, z):
    hello.append(for_s(thing))
    hello.append(for_k(thing))

print(min(hello))

cards = input().split()
m = []
s = []
p = []

for i in range(3):
    if cards[i][1] == "m":
        m.append(int(cards[i][0]))
    elif cards[i][1] == "s":
        s.append(int(cards[i][0]))
    elif cards[i][1] == "p":
        p.append(int(cards[i][0]))

msp = [m, s, p]
rmsp = [len(m), len(s), len(p)]

if rmsp[0] == rmsp[1] == rmsp[2]:
    print(2)

def con3(seq):
    seq.sort()
    new_seq = [seq[1]-seq[0], seq[2]-seq[0]]
    n_seq = new_seq[1] - new_seq[0]
    if new_seq == [1,2] or new_seq == [0,0]:
        print(0)
    elif new_seq[0] == 1 or new_seq[1] == 1 or n_seq == 0 or n_seq == 1 or n_seq == 2 or new_seq[0] == 2 or new_seq[1] == 2 or new_seq[0] == 0:
        print(1)
    else:
        print(2)

def con2(seq):
    cons = abs(seq[1] - seq[0])
    if cons == 0 or cons == 1 or cons == 2:
        print(1)
    else:
        print(2)

for i in range(3):
    if rmsp[i] == 3:
        con3(msp[i])
        break
    elif rmsp[i] == 2:
        val2 = msp[i]
        con2(val2)
        break

import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

def main():
    # something
    pie = input().split()
    man = []
    pin = []
    soh = []
    for p in pie:
        if p.endswith("p"):
            pin.append(p)
        elif p.endswith("s"):
            soh.append(p)
        else:
            man.append(p)

    ans = 2
    for mark in [man, pin, soh]:
        # print(mark)
        nums = sorted([int(m[0]) for m in mark])
        if len(mark) <= 1:
            pass

        elif len(mark) == 2:
            # print("here")

            if mark[0] == mark[1]:
                ans = 1
            if nums[1] - nums[0] <= 2:
                ans = 1

        else:
            # print("nohre")
            # print(mark)
            if nums[0] == nums[1] and nums[1] == nums[2]:
                ans = 0
                break
            if nums[1] - nums[0] == 1:
                if nums[2] - nums[1] == 1:
                    ans = 0
                else:
                    ans = 1
                break

            if nums[2] - nums[1] == 1:
                if nums[1] - nums[0] == 1:
                    ans = 0
                else:
                    ans = 1
                break

            if nums[1] - nums[0] == 2 or nums[2] - nums[1] == 2:
                ans = 1
                break

            if len(list(set(nums))) == 2:
                ans = 1
                break

    print(ans)

if __name__ == "__main__":
    main()

def smaller(x, y):
	if x < y:
		return x
	return y

def kohtsu(a, b, c):
	if a == b:
		if b == c:
			return 0
		else:
			return 1
	return 2

def shuntsu(a, b, c):
	if a[1] == b[1]:
		if int(a[0])+2 == int(b[0]):
			if (c[1] == a[1]) and (int(a[0])+1 == int(c[0])):
				return 0
			else:
				return 1
		if int(a[0])+1 == int(b[0]):
			if (c[1] == a[1]) and (int(a[0])-1 == int(c[0]) or int(b[0])+1 == int(c[0])):
				return 0
			else:
				return 1
	return 2

inpt = input().split()
ans = 2
ans = smaller(ans, kohtsu(inpt[0], inpt[1], inpt[2]))
ans = smaller(ans, shuntsu(inpt[0], inpt[1], inpt[2]))
ans = smaller(ans, kohtsu(inpt[0], inpt[2], inpt[1]))
ans = smaller(ans, shuntsu(inpt[0], inpt[2], inpt[1]))
ans = smaller(ans, kohtsu(inpt[1], inpt[0], inpt[2]))
ans = smaller(ans, shuntsu(inpt[1], inpt[0], inpt[2]))
ans = smaller(ans, kohtsu(inpt[1], inpt[2], inpt[0]))
ans = smaller(ans, shuntsu(inpt[1], inpt[2], inpt[0]))
ans = smaller(ans, kohtsu(inpt[2], inpt[0], inpt[1]))
ans = smaller(ans, shuntsu(inpt[2], inpt[0], inpt[1]))
ans = smaller(ans, kohtsu(inpt[2], inpt[1], inpt[0]))
ans = smaller(ans, shuntsu(inpt[2], inpt[1], inpt[0]))

print(ans)

t = input().strip().split()

m = 3

for i in range(1, 8):
    for j in 'mps':
        r = 3
        if str(i) + j in t: r -= 1
        if str(i+1) + j in t: r -= 1
        if str(i+2) + j in t: r -= 1
        m = min(m, r)

print(min(m, len(set(t)) - 1))

a = input().split()
res = 2
for i in range(1, 10):
    for j in "smp":
        #print(str(i) + j, 3 - (str(i) + j in a) - (str(i+1) + j in a) - (str(i+2) + j in a))
        res = min(res, 3 - (str(i) + j in a) - (str(i+1) + j in a) - (str(i+2) + j in a))
        res = min(res, 3 - a.count(str(i) + j))
print(res)

"""
NTC here
"""
from sys import setcheckinterval, stdin
setcheckinterval(1000)

# print("Case #{}: {} {}".format(i, n + m, n * m))

iin = lambda: int(stdin.readline())
lin = lambda: list(map(int, stdin.readline().split()))

def check1(a):
    if not a:
        return 3
    n=len(a)
    ans=1
    for i in range(n):
        sola={a[i]:1}
        if a[i]+1<10:
            sola[a[i]+1]=0
        if a[i]+2<10:
            sola[a[i]+2]=0
        if a[i]-1>0:
            sola[a[i]-1]=0
        if a[i]-2>0:
            sola[a[i]-2]=0
        j=i+1
        while j<n:
            try:
                sola[a[j]]=1
            except:pass
            j+=1
        if a[i]-1 in sola and a[i]-2 in sola:
            ans=max(ans,sola[a[i]]+sola[a[i]-1]+sola[a[i]-2])
        if a[i]-1 in sola and a[i]+1 in sola:
            ans=max(ans,sola[a[i]]+sola[a[i]-1]+sola[a[i]+1])
        if a[i]+1 in sola and a[i]+2 in sola:
            ans=max(ans,sola[a[i]]+sola[a[i]+1]+sola[a[i]+2])

    return 3-ans

def check2(a):
    if not a:return 3
    d={}
    for i in a:
        try:
            d[i]+=1
        except:
            d[i]=1
    return 3-max(d.values())

s=input().split()
a1=[];a2=[];a3=[]

for i in s:
    if i[1]=='m':
        a1.append(int(i[0]))
    elif i[1]=='p':
        a2.append(int(i[0]))
    elif i[1]=='s':
        a3.append(int(i[0]))
a1.sort()
a2.sort()
a3.sort()

ans=min(check1(a1),check1(a2),check1(a3),check2(s))
print(ans)
# print(check1(a1),check1(a2),check1(a3),check2(s),a1,a2,a3)

def f(a, b, c):
    if a[0] > b[0]:
        a, b = b, a
    if abs(int(a[0]) - int(b[0])) == 1 and a[1] == b[1]:
        if a[1] == c[1] and abs(int(c[0]) - int(b[0])) == 1 and a != c:
            return 0
        else:
            return 1
    if abs(int(a[0]) - int(b[0])) == 2 and a[1] == b[1]:
        return 1
    return 2

a, b, c = input().split()
s1 = set()
s1.add(a)
s1.add(b)
s1.add(c)
c1 = len(s1) - 1
print(min(c1, f(a, b, c), f(a, c, b), f(b, c, a)))

import sys,math

def read_int():
    return int(sys.stdin.readline().strip())

def read_int_list():
    return list(map(int,sys.stdin.readline().strip().split()))

def read_string():
    return sys.stdin.readline().strip()

def read_string_list(delim=" "):
    return sys.stdin.readline().strip().split(delim)

def print_list(l, delim=" "):
    print(delim.join(map(str, l)))

###### Author : Samir Vyas #######
###### Write Code Below    #######

tiles = read_string_list()

#all equal
if tiles[0] == tiles[1] == tiles[2]:
	print(0)
	sys.exit()

#any two equal
if tiles[0] == tiles[1] or tiles[1] == tiles[2] or tiles[2] == tiles[0]:
	print(1)
	sys.exit()

mps = {"m":[], "p":[], "s":[]}

for t in tiles:
	mps[t[1]] += [int(t[0])]

for k in mps:
	mps[k].sort()

#3 of same
for k in mps:
	if len(mps[k]) == 3:
		l = mps[k]
		if l[0]+1 == l[1] and l[1]+1 == l[2]:
			print(0)
			sys.exit()
		if l[1]-l[0] <= 2 or l[2]-l[1] <= 2:
			print(1)
			sys.exit()

#2 of same
for k in mps:
	if len(mps[k]) == 2:
		l = mps[k]
		if l[1]-l[0] <=2 :
			print(1)
			sys.exit()

#no luck
print(2)

li = list(map(str,input().split()))
lis=[ i[1]+i[0] for i in li]
lis.sort()
ans=[]
ans.append(1)
for i in range(1,len(lis)):
    if lis[i]==lis[i-1]:
        ans[-1]+=1
    else:
        ans.append(1)
an=min(max(ans),3)
#print(ans,lis)
if an==3:
    print('0')
    exit()
ans=[]
ans.append(1)
for i in range(1,len(lis)):
    if lis[i]==lis[i-1]:
        continue
    if int(lis[i][1])==int(lis[i-1][1])+1 and lis[i][0]==lis[i-1][0]:
        ans[-1]+=1
    elif int(lis[i][1])==int(lis[i-1][1])+2 and lis[i][0]==lis[i-1][0]:
        ans.append(2)
        ans.append(1)
    else:
        ans.append(1)
print(3-min(3,max(max(ans),an)))

# Main

data = [x for x in raw_input().split(" ")]
sol = None

if len(set(data)) == 1:
	sol = 0

elif data[0][1] == data[1][1] and data[0][1] == data[2][1]:
	nums = [int(data[0][0]), int(data[1][0]), int(data[2][0])]
	nums.sort()
	if nums[0] == nums[1] - 1:
		if nums[1] == nums[2] - 1:
			sol = 0
		else:
			sol = 1
	else:
		if nums[1] == nums[2] - 1:
			sol = 1

elif len(set(data)) == 2:
	if sol != 0:
		sol = 1

# I think this entire block is redundants since I handled it in the
# check above... That said, I don't think it'll hurt - worst case if
# I'm right, it'll just fire down this branch in the case of a 2

if sol == None:
	if data[0][1] == data[1][1]:
		if abs(int(data[0][0]) - int(data[1][0])) <= 2:
			# they're off by one and we only need one more piece
			sol = 1

	if data[0][1] == data[2][1]:
		if abs(int(data[0][0]) - int(data[2][0])) <= 2:
			# they're off by one and we only need one more piece
			sol = 1

	if data[1][1] == data[2][1]:
		if abs(int(data[1][0]) - int(data[2][0])) <= 2:
			# they're off by one and we only need one more piece
			sol = 1

if sol == None:
	sol = 2

print sol

tiles = {
	'm': [],
	'p': [],
	's': []
}
for tile in input().split():
	tiles[tile[1]].append(int(tile[0]))
max_ava = 0
for suit in tiles:
	# max for seq
	for x in range(1, 10):
		seq = 0
		if x in tiles[suit]:
			seq += 1
		if x+1 in tiles[suit]:
			seq += 1
		if x+2 in tiles[suit]:
			seq += 1
		max_ava = max(max_ava, seq)
	# max for grp
	for x in range(1, 10):
		count = tiles[suit].count(x)
		max_ava = max(max_ava, count)
print(3 - max_ava)

suit=list(map(str,input().split()))
suit=sorted(suit)
number=[]
alpha=[]
counts=0
countm=0
countp=0
if suit[0]==suit[1] and suit[1]==suit[2]:
    print('0')
    exit()
for i in range(len(suit)):
    number.append(int(suit[i][0]))
    alpha.append(suit[i][1])
    if suit[i][1]=='s':
        counts+=1
    if suit[i][1]=='m':
        countm+=1
    if suit[i][1]=='p':
        countp+=1
if number[1]==number[0]+1 and number[2]==number[1]+1 and alpha[0]==alpha[1] and alpha[1]==alpha[2]:
    print('0')
    exit()
if max(counts,countm,countp)==3:
    if number[2]-number[1]>2 and number[1]-number[0]>2:
        print('2')
    else:
        print('1')
elif max(counts,countm,countp)==2:
    if alpha[0]==alpha[1]:
        if number[1]-number[0]>2:
            print('2')
        else:
            print('1')
    elif alpha[1]==alpha[2]:
        if number[2]-number[1]>2:
            print('2')
        else:
            print('1')
    else:
        if number[2]-number[0]>2:
            print('2')
        else:
            print('1')
else:
    print('2')

from collections import defaultdict as dfd

d = dfd(int)
arr = input().split()
arr.sort()

for i in arr:
    d[i] += 1

if max(d.values())==3 or (arr[0][1]==arr[1][1]==arr[2][1] and int(arr[0][0])+1==int(arr[1][0]) and int(arr[1][0])+1==int(arr[2][0])):
    print(0)
elif max(d.values())==2:
    print(1)
else:
    flag = True
    for i in range(len(arr)):
        for j in range(i+1, len(arr)):
            if arr[i][1]==arr[j][1] and (abs(int(arr[i][0])-int(arr[j][0]))==1 or abs(int(arr[i][0])-int(arr[j][0]))==2):
                print(1)
                flag = False
                break
        if not flag:
            break
    if flag:
        print(2)

# In[10]:

m = {}
p = {}
s = {}
for i in range(1,10):
    p[str(i)+'p'] = i
    s[str(i)+'s'] = i
    m[str(i)+'m'] = i
card = []
card.append(m)
card.append(p)
card.append(s)

# In[12]:

a = input()
tmp = a.split(' ')

# In[13]:

ma = [[],[],[]]
for obj in tmp:
    if obj in card[0]:
        ma[0].append(int(obj[0]))
    elif obj in card[1]:
        ma[1].append(int(obj[0]))
    else:
        ma[2].append(int(obj[0]))
for i in range(3):
    list.sort(ma[i])

# In[15]:

output = 1
save = 0
max_count = 0
three = []
for i in range(3):
    for j in range(1,10):
        fuck = 0
        for k in range(len(ma[i])):
            if ma[i][k] == j:
                fuck += 1
        three.append(fuck)

if max(three) >= 3:
    output = 0
elif max(three) == 2:
    output = 1
else:
    output = 2
index = 2
for i in range(3):
    if output == 0:
        break
    n = len(ma[i])
    count = 0
    for j in range(n):
        if j == 0:
            save = ma[i][j]
        else:
            if save - ma[i][j] == -1:
                count += 1
                if count == 2:
                    index = 0
                    break
                elif count == 1:
                    index = 1
            elif save - ma[i][j] == -2:
                index = 1
            else:
                if count == 1:
                    index = 1
                count = 0
            save = ma[i][j]
    if index == 0:
        break

print(min(output,index))
# In[ ]:

tiles = input().split()

tile0s = tiles[0][1]
tile1s = tiles[1][1]
tile2s = tiles[2][1]

tile0v = int(tiles[0][0])
tile1v = int(tiles[1][0])
tile2v = int(tiles[2][0])

tvals = sorted ([tile0v, tile1v, tile2v])

if tiles[0] == tiles[1] and tiles[0] == tiles[2]:
    print (0)
elif tile0s == tile1s and tile1s == tile2s and tvals[1] == tvals[0] +1 and tvals[2] == tvals[1] +1:
    print(0)
elif tiles[0] == tiles[1] or tiles[0] == tiles[2] or tiles[1] == tiles[2]:
    print(1)
elif ((tile0s == tile1s and abs(tile0v - tile1v) <=2) or
      (tile0s == tile2s and abs(tile0v - tile2v) <=2) or
      (tile2s == tile1s and abs(tile2v - tile1v) <=2)):
    print(1)
else:
    print(2)

a = sorted(input().split())

if a[0] == a[1] == a[2]:
    print(0)
elif (a[0][1] == a[1][1] == a[2][1]) and (int(a[0][0]) + 1 == int(a[1][0]) and int(a[1][0]) + 1 == int(a[2][0])):
    print(0)
elif a[0] == a[1] or a[1] == a[2]:
    print(1)
else:
    s = set(a)
    r = None
    for e in s:
        num, word = int(e[0]), e[1]
        if str(str(num - 2) + word) in s or str(str(num - 1) + word) in s or str(str(num + 1) + word) in s or str(
                str(num + 2) + word) in s:
            r = 1
            break
    if r:
        print(r)
    else:
        print(2)

l = list(input().split())

d = {}
d["m"] = {}
d["s"] = {}
d["p"] = {}
for i in range(1,10):
    d["m"][i] = 0
    d["s"][i] = 0
    d["p"][i] = 0

for a in l:
    s = a[1]
    c = int(a[0])
    d[s][c] += 1

#koutsu
c = 0
for s in ["m","p","s"]:
    for i in range(1,10):
        c = max(c,d[s][i])
        if c >= 3:
            print(0)
            exit()

ans = 3 - c
#shuusu
t = 0
for s in ["m","p","s"]:
    c = 0
    for i in range(1,10):
        if d[s][i] != 0:
            c += 1
        else:
            t = max(t,c)
            if t >= 3:
                print(0)
                exit()
            c = 0
    t = max(t,c)

    c = 0
    for i in range(1,8):
        if d[s][i] != 0 and  d[s][i+2] != 0:
            c = 2
            break
    t = max(t,c)

print(min(ans , 3 - t))

ll= lambda : list(map(int,input().split()))
testcases=1
# testcases=int(input())
for testcase in range(testcases):
	s1,s2,s3=input().split()
	ss=[s1,s2,s3]
	ss.sort()
	if(len(set([i[1] for i in ss]))==1):
		if(len(set([i[0] for i in ss]))==1 or ((int(ss[0][0])==int(ss[1][0])-1) and (int(ss[0][0])==int(ss[2][0])-2))):
			print(0)
		elif ((len(set([i[0] for i in ss]))==2) or (int(ss[0][0])==int(ss[1][0])-1) or (int(ss[0][0])==int(ss[1][0])-2) or (int(ss[1][0])==int(ss[2][0])-1)):
			print(1)
		else:
			print(2)
	elif(len(set([i[1] for i in ss]))==2):
		ans=2
		for i in range(0,2):
			for j in range(i+1,3):
				if ss[i][1]==ss[j][1]:
					if(ss[i][0]==ss[j][0] or abs(int(ss[i][0])-int(ss[j][0]))<=2):
						# print(i,j)
						ans=1
						break
			if(ans==1):
				break
		print(ans)
	else:
		print(2)

a,b,c=input().split()
def fine(x):
    if x[0]==x[1] and x[1]==x[2]:
        return True
    if x[0][1]==x[1][1] and x[1][1]==x[2][1]:
        if (int(x[0][0])+1)==int(x[1][0]) and (int(x[0][0])+2)==int(x[2][0]):
            return True
    return False
l=[a,b,c]
for i in range(3):
    for j in range(3):
        for k in range(3):
            if i==j or i==k or j==k:
                continue
            if fine([l[i],l[j],l[k]]):
                print(0)
                quit()
for ijk in range(1,10):
    for x in ['m','p','s']:
        s=str(ijk)+x
        l=[a,b,c,s]
        for i in range(4):
            for j in range(4):
                for k in range(4):
                    if i==j or i==k or j==k:
                        continue
                    if fine([l[i],l[j],l[k]]):
                        print(1)
                        quit()
print(2)

'''

1. Figure out min number to get a kontsu

   Get a 'counter', count exact match.
     - 3 - find max value

2. Figure out min number to get a mentsu

   Sort the cards

   Do a while loop

   While i is < len(lst)

     Count # of consecutive cards

     Move j until index of the last consecutive card

'''

def min_mentsu(cards):
    return min(min_koutsu(cards), min_shuntsu(cards))

def min_koutsu(cards):
    counter = {}

    for card in cards:
        if card not in counter:
            counter[card] = 0
        counter[card] += 1

    return max(0, 3 - max(counter.values()))

def min_shuntsu(cards):
    '''
    Cases:

    3 same:

    2 same: either consecutive

    7p 8p or 7p 9p

    '''

    cards = sorted([(int(card[0]), card[1]) for card in cards], key=lambda x: (x[1], x[0]))

    if consecutive(cards, 0) and consecutive(cards, 1):
        return 0

    if consecutive(cards, 0) or consecutive(cards, 1):
        return 1

    if jump_consecutive(cards, 0) or jump_consecutive(cards, 1):
        return 1

    return 2

def consecutive(cards, i):
    num, suit = cards[i]
    num2, suit2 = cards[i + 1]

    return suit == suit2 and num2 - num == 1

def jump_consecutive(cards, i):
    num, suit = cards[i]
    num2, suit2 = cards[i + 1]

    r = (suit == suit2) and (num2 - num == 2)
    return r

cards = raw_input().split()
print min_mentsu(cards)

a, b, c = input().split()

numbers = [int(a[0]), int(b[0]), int(c[0])]
letters = [a[1], b[1], c[1]]
if (a == b == c):
	print(0)

else:
	order = sorted(numbers)
	flag = 0
	for i in range(2):
		diff = order[i + 1] - order[i]
		if (diff != 1):
			flag = 1
			break
	if(flag == 0):
		print(0)

	else:
		#print(letters)
		p = letters.count("p")
		m = letters.count("m")
		s = letters.count("s")
		#print(m, p, s)
		if(p == 1 and m == 1 and s == 1):#each of diff type
			print(2)

		else:
			if (m == 3 or p == 3 or s == 3):
				order = sorted(numbers)
				diff = []
				for i in range(2):
					diff.append(order[i + 1] - order[i])
				if(1 in diff or 2 in diff):
					print(1)
				elif(0 in diff):
					print(2)
			else:
				#1, 2
				if (letters[0] == letters[1]):
					twos = [numbers[0], numbers[1]]
				elif(letters[0] == letters[2]):
					twos = [numbers[0], numbers[2]]
				else:
					twos = [numbers[1], numbers[2]]

				if (abs(twos[1] - twos[0]) == 1 or abs(twos[1] - twos[0]) == 2):
					print(1)
				else:
					print(2)

import sys
import math
import bisect
import atexit
import io
import heapq
from collections import defaultdict, Counter
MOD = int(1e9+7)

# n = map(int, raw_input().split())
# input = map(int, raw_input().split())
def main():
    a, b, c = raw_input().split()
    d = defaultdict(list)
    num = []
    ans = 2
    for st in (a,b,c):
        nu, ch = st
        nu = int(nu)
        d[ch].append(int(nu))
        num.append(nu)
    num.sort()
    if num[0] == num[-1]-2:
        ans = 0
    if num[0] == num[1]-2 or num[1] == num[-1]-2:
        ans = min(ans, 1)
    for k, v in d.items():
        v.sort()
        if len(v) == 3:
            ans = 0
        elif len(v)==2:
            ans = min(ans, 1)
    print ans

main()

from __future__ import print_function
import sys

def get_seq(line):
    a = sorted(line.split())
    d = {'m': [], 'p': [], 's': []}
    for x in a:
        n = ord(x[0]) - ord('0')
        d[x[1]].append(n)

    l = [(len(l), l) for l in d.values()]
    l.sort(reverse=True)
    return sorted(l[0][1])

def get_best(a):
    if len(a) == 1:
        return 2
    elif len(a) == 2:
        if (a[1] - a[0]) % 2 == 0:
            return 1
        elif 2 * a[0] - a[1] >= 1:
            return 1
        elif 2 * a[1] - a[0] <= 9:
            return 1
        else:
            return 2
    elif len(a) == 3:
        if a[1] * 2 == a[0] + a[2]:
            return 0
        else:
            return 1

seq = get_seq(input())
print(seq, file=sys.stderr)
print(get_best(seq))

l = list(input().split())
d = {}
for i in l:
    if i[1] not in d:d[i[1]] = [int(i[0])]
    else:
        d[i[1]].append(int(i[0]))
best = []
for i in d:
    if len(d[i]) > len(best):
        best = d[i]
if len(best)==1:print(2)
elif len(set(best))==1:print(3-len(best))
else:
    m = min(best)
    if m+1 in best:
        if m+2 in best:print(0)
        else:print(1)
    elif m+2 in best or best.count(m)==2:
        print(1)
    else:
        print(2)

cards = input().split()
ans = 2
if cards[0] == cards[1] and cards[2] == cards[1]:
    ans = 0
elif cards[0] == cards[1] or cards[0] == cards[2] or cards[2] == cards[1]:
    ans = 1
else:
    if cards[0][1] == cards[1][1] and cards[0][1] == cards[2][1]:
        if abs(int(cards[0][0]) - int(cards[1][0])) <= 2 and abs(int(cards[0][0]) - int(cards[2][0])) <= 2 and abs(int(cards[1][0]) - int(cards[2][0])) <= 2:
            ans = 0
        elif abs(int(cards[0][0]) - int(cards[1][0])) == 1 or abs(int(cards[0][0]) - int(cards[2][0])) == 1 or abs(int(cards[1][0]) - int(cards[2][0])) == 1:
            ans = min(ans, 1)
    elif not(cards[0][1] != cards[1][1] and cards[0][1] != cards[2][1] and cards[2][1] != cards[1][1]):
        if cards[0][1] == cards[1][1]:
            card1, card2 = cards[0], cards[1]
        elif cards[0][1] == cards[2][1]:
            card1, card2 = cards[0], cards[2]
        else:
            card1, card2 = cards[1], cards[2]
        if abs(int(card1[0]) - int(card2[0])) == 1:
            ans = min(ans, 1)
print(ans)

def similar_number(arr):
    m = 1
    for i in range(1, 10):
        i_cnt = arr.count(i)
        m = max(i_cnt, m)
    return m

def subseq_num(arr):
    if len(arr) == 0 or len(arr) == 1:
        return 1

    arr.sort()

    if len(arr) == 2:
        if arr[1] == arr[0] + 1 or arr[1] == arr[0] + 2:
            return 2
        else:
            return 1

    if arr[2] - arr[0] == 2:
        return 3
    elif arr[2] == arr[1] + 1 or arr[1] == arr[0] + 1:
        return 2
    else:
        return 1

def solve():

    cards = input().split()

    s_cards = list(filter(lambda c: c[1] == 's', cards))
    m_cards = list(filter(lambda c: c[1] == 'm', cards))
    p_cards = list(filter(lambda c: c[1] == 'p', cards))

    s_numbers = list(map(lambda c: int(c[0]), s_cards))
    m_numbers = list(map(lambda c: int(c[0]), m_cards))
    p_numbers = list(map(lambda c: int(c[0]), p_cards))

    s_n = similar_number(s_numbers)
    m_n = similar_number(m_numbers)
    p_n = similar_number(p_numbers)

    s_s = subseq_num(s_numbers)
    m_s = subseq_num(m_numbers)
    p_s = subseq_num(p_numbers)

    _n = max(s_n, m_n, p_n, s_s, m_s, p_s)

    print(3 - _n)

solve()

cards= list(map(str,input().split()))
dict={'p':[],'m':[],'s':[]}
min_draw=2
for i in cards:
    dict[str(i)[1]].append(int(str(i)[0]))
for j in dict.keys():
    m=len(dict[j])-len(set(dict[j]))
    if min_draw>2-m:
        min_draw=2-m
    dict[j].sort()
    if len(dict[j])==3:
        n=2
        if dict[j][2]-dict[j][0]==2:
           n=0
        else:
            if dict[j][1]-dict[j][0]<=2 or dict[j][2]-dict[j][1]<=2:
                n=1
        if min_draw>n:
            min_draw=n
    if len(dict[j])==2:
        if dict[j][1]-dict[j][0]<=2:
            if min_draw>1:
                min_draw=1

print(min_draw)

a=list(input().split())
ar1=[]
ar2=[]
for i in a:
    ar1.append(int(i[0]))
    ar2.append(i[1])
s=set()
for i in range(3):
    for j in range(i,3):
        if ar2[i]==ar2[j]:
            s.add(i)
            s.add(j)
if len(s)==0:
    print(2)
elif len(s)==2:
    i1=s.pop()
    i2=s.pop()
    if abs(ar1[i1]-ar1[i2])<=1:
        print(1)
    else:
        print(2)
else:
    ar1.sort()
    d1=ar1[1]-ar1[0]
    d2=ar1[2]-ar1[1]
    if d1==0:
        if d2==0:
            print(0)
        else:
            print(1)
    elif d1==1:
        if d2==1:
            print(0)
        else:
            print(1)
    else:
        if d2==0 or d2==1:
            print(1)
        else:
            print(2)

def solve(arr):
    d = Counter(arr)
    mx  = 0
    for i in d.keys():
        mx = max(mx,d[i])
    if mx >= 3:
        return 0
    d1 = {'m':[],'p':[],'s':[]}
    for a,v in arr:
        d1[v].append(int(a))
    count = 0
    #print(d1)
    for key in d1.keys():
        if len(d1[key]) > 0:
            d1[key].sort()
            local = 1
            for j in range(len(d1[key])-1):
                if d1[key][j+1] - d1[key][j]==1:
                    local += 1
                else:
                    count = max(count,local)
                    local = 0
            count = max(count,local)
            #print("heer",count)
    if count >= 3:
        return 0
    return 3 - max(mx,count)

from collections import Counter
arr = input()
arr = arr.split()
print(solve(arr))

l = list(input().split())
d = {}
for i in l:
    if i[1] not in d:d[i[1]] = [int(i[0])]
    else:
        d[i[1]].append(int(i[0]))
best = []
for i in d:
    if len(d[i]) > len(best):
        best = d[i]
if len(best)==1:print(2)
elif len(set(best))==1:print(3-len(best))
else:
    m = min(best)
    if m+1 in best:
        if m+2 in best:print(0)
        else:print(1)
    elif m+2 in best:
        print(1)
    elif m in best:
        print(1)
    else:
        print(0)

from collections import defaultdict
def main():
# ****************************** Input *************************************
    A=list(input().split())
    # print(A)

# ****************************** Algorithm *********************************
    B=sorted(A,key = lambda x : int(x[0]))
    m=defaultdict(list)
    for i in B:
        m[i[1]].append(int(i[0]))
    # print(m)
    # Now check for mentsu
    # Check for Koutsu
    # Formed when in any of m,s,p there are 3 numbers the same
    maxCount=0
    for i in m:
        count1=0
        for j in range(len(m[i])-1):
            # print(m[i][j],m[i][j+1])
            if m[i][j] == m[i][j+1]:
                count1+=1
                # print("Run",count1)
            else:
                count1=0
            if count1>maxCount:
                maxCount=count1
            if count1==2:
                print(0)
                return
    # Check for Shuntsu
    for i in m:
        count2=0
        for j in range(len(m[i])-1):
            if m[i][j] + 1 ==m[i][j+1]:
                count2+=1
            else:
                count2=0
            if count2 > maxCount:
                maxCount = count2
            if count2 == 2:
                print(0)
                return
    # print(maxCount)
    # THird Case
    print(m)
    if maxCount==0:
        for i in m:
            # count3=0
            for j in range(len(m[i])-1):
                # print(m[i][j],m[i][j+1])
                if abs(m[i][j] - m[i][j+1]) == 2:
                    print(1)
                    return

# ****************************** output ************************************
#Output here
    print(m)
    if len(A)==0:
        print(3)
    else:
        print(2-maxCount)

main()
# 5p 5s 9m 4p 1s 7p 7m 6p
# 2m 3p 2s 4m 1s 2s 4s

# 3m 9m 2m

a,b,c=input().split()
def fine(x):
    if x[0]==x[1] and x[1]==x[2]:
        return True
    if x[0][1]==x[1][1] and x[1][1]==x[2][1]:
        if (int(x[0][0])+1)==int(x[1][0]) and (int(x[0][0])+2)==int(x[2][0]):
            return True
    return False
l=[a,b,c]
for i in range(3):
    for j in range(3):
        for k in range(3):
            if i==j or i==k or j==k:
                continue
            if fine([l[i],l[j],l[k]]):
                print(0)
                quit()
for ijk in range(1,10):
    for x in ['m','p','s']:
        s=str(ijk)+x
        l=[a,b,c,s]
        for i in range(4):
            for j in range(4):
                for k in range(4):
                    if i==j or i==k or j==k:
                        continue
                    if fine([l[i],l[j],l[k]]):
                            quit()
print(2)

def solve(arr):
    d = Counter(arr)
    mx  = 0
    for i in d.keys():
        mx = max(mx,d[i])
    if mx >= 3:
        return 0
    d1 = {'m':[],'p':[],'s':[]}
    for a,v in arr:
        d1[v].append(int(a))
    count = 0
    counttwo = 0
    #print(d1)
    for key in d1.keys():
        if len(d1[key]) > 0:
            d1[key].sort()
            local = 1
            localtwo  = 1
            for j in range(len(d1[key])-1):
                if d1[key][j+1] - d1[key][j]==1:
                    local += 1
                else:
                    count = max(count,local)
                    local = 0

                if d1[key][j+1] - d1[key][j]==2:
                    localtwo += 1
                else:
                    counttwo = max(counttwo,localtwo)
                    localtwo = 0
            count = max(count,local)
            counttwo = max(counttwo,localtwo)
            #print("heer",count,counttwo)
    if count >= 3:
        return 0
    if counttwo>1:
        return min(3 - max(mx,count),1)
    return 3 - max(mx,count)

from collections import Counter
arr = input()
arr = arr.split()
print(solve(arr))

t = sorted(input().split())
ans = 3
l = 0
while l < len(t):
    r = l
    while r < len(t) and t[r] == t[l]:
        r += 1
    ans = min(ans, 3 - (r - l))
    l = r
t = sorted(list(set(t)), key=lambda e: e[1] + e[0])
l = 0
while l < len(t):
    r = l
    while r < len(t) and t[r][1] == t[l][1]:
        r += 1
    for k in range(l, r):
        ans = min(ans, 2)
        if k + 1 < r:
            if int(t[k + 1][0]) == int(t[k][0]) + 1:
                ans = min(ans, 1)
            if k + 2 < r:
                if int(t[k + 2][0]) == int(t[k][0]) + 2:
                    ans = min(ans, 0)
    l = r
print(ans)

a, b, c = input().split()

if a == b and b == c :
	print("0")
else :
	ok = False
	if a[1] == b[1] and b[1] == c[1] :
		aa, bb, cc = int(a[0]), int(b[0]), int(c[0])
		l = [aa, bb, cc]
		l.sort()
		if l[0] == l[1]-1 and l[1] == l[2]-1 :
			ok = True
	if ok :
		print("0")
	else :
		if a == b or b == c :
			print("1")
		else :
			if a[1] == b[1] or b[1] == c[1] or a[1] == c[1] :
				aa, bb, cc = int(a[0]), int(b[0]), int(c[0])
				if ((aa == bb-1 or aa-1 == bb) and a[1] == b[1]) :
					print("1")
				elif ((aa == cc-1 or aa-1 == cc) and a[1] == c[1]) :
					print("1")
				elif ((cc == bb-1 or cc-1 == bb) and b[1] == c[1]) :
					print("1")
				else :
					print("2")
			else :
				print("2")

a, b, c = map(str, input().split())
d = []
for i in range(3):
    d.append([0] * 9)

def f(k):
    if k[1] == 'm':
        d[0][int(k[0]) - 1] += 1
    elif k[1] == 'p':
        d[1][int(k[0]) - 1] += 1
    else:
        d[2][int(k[0]) - 1] += 1
f(a)
f(b)
f(c)
min_m = 2
if max(d) == 2:
    print(0)
elif max(d):
    min_m = min(1, min_m)
else:
    for j in range(3):
        for i in range(1, 8):
            if d[j][i] == 1:
                if d[j][i - 1] + d[j][i + 1] == 1:
                    min_m = min(1, min_m)
                elif d[j][i - 1] == d[j][i + 1] == 1:
                    min_m = min(0, min_m)
                    print(min_m)
            else:
                if d[j][i - 1] == d[j][i + 1] == 1:
                    min_m = min(1, min_m)
min_m = min(2, min_m)
print(min_m)

# Coding credits Moaz Adnan
my_String = list(raw_input().split())
num = []
letter =[]
for item in my_String:
	letter.append(item[1])
	num.append(int(item[0]))
if len(set(my_String)) == 1:
	print (0)
elif len(set(letter)) <= 2:
	if num[0] == num[1] or num[1] == num[2] or num[0] == num[2]:
		print(1)
	elif abs(num[0] - num[1]) + abs(num[1] - num[2]) == 3:
		print(0)
	else:
		print(2)
else:
	print(2)

cards= list(map(str,input().split()))
dict={'p':[],'m':[],'s':[]}
min_draw=2
for i in cards:
    dict[str(i)[1]].append(int(str(i)[0]))
for j in dict.keys():
    m=3-len(dict[j])
    if min_draw>m:
        min_draw=m
    dict[j].sort()
    if len(dict[j])==3:
        n=2
        if dict[j][2]-dict[j][0]==2:
           n=0
        else:
            if dict[j][1]-dict[j][0]<=2 or dict[j][2]-dict[j][1]<=2:
                n=1
        if min_draw>n:
            min_draw=n
    if len(dict[j])==2:
        if dict[j][1]-dict[j][0]<=2:
            if min_draw>1:
                min_draw=1

print(min_draw)

import sys

ss = sys.stdin.readline().replace('\n', '').split()

def brick (sb):
	return (int(sb[0]), sb[1])

ss = map(brick, ss)
ss = sorted(ss)
a = ss[0]
b = ss[1]
c = ss[2]

if ss[0] == ss[1] and ss[1] == ss[2]:
	print "0"
elif a[1] == b[1] and b[1] == c[1] and a[0] == b[0]-1 and b[0] == c[0]-1:
	print "0"
elif a == b or b == c or a == c:
	print "1"
elif (a[1] == b[1] and a[0] == b[0]-1) or (b[1] == c[1] and b[0] == c[0]-1) or (a[1] == c[1] and a[0] == c[0]-1):
	print "1"
else:
	print "2"

l=input().split()
if(len(set(l))==1):
	print(0)
else:
	d=dict()
	#d1=dict('s':0,'m':0;'p':0)
	for i in l:
		if(i[1] not in d):
			d[i[1]]=[int(i[0])]
		else:

			d[i[1]].append(int(i[0]))
	mi=9
	for i in d.values():
		if(len(i)>0):
			i.sort()
			if(len(i)==3):

				c=[]
				for j in range(0,2):
					c.append(i[j+1]-i[j])
				x=min(c)
				if(x==1 and c.count(1)==2):
					mi=0
				elif(x==2):
					if(mi>1):
						mi=1
				elif(x==0):
					y=c.count(0)
					y=3-y
					if(y<mi):
						mi=y
				else:
					if(mi>3):
						mi=3

			elif(len(i)==2):
				x=i[1]-i[0]
				if(x==0):
					mi=0
				else:
					if(x<mi):
						mi=x
			else:
				x=2
				if(mi>x):
					mi=x
		else:
			if(mi>3):
				mi=3
	print(mi)

a, b, c = map(str, input().split())
d = []
for i in range(3):
    d.append([0] * 9)

def f(k):
    if k[1] == 'm':
        d[0][int(k[0]) - 1] += 1
    elif k[1] == 'p':
        d[1][int(k[0]) - 1] += 1
    else:
        d[2][int(k[0]) - 1] += 1
f(a)
f(b)
f(c)
min_m = 2
if max(max(d)) == 3:
    min_m = min(0, min_m)
elif max(max(d)) == 2:
    min_m = min(1, min_m)
else:
    for j in range(3):
        for i in range(1, 8):
            if d[j][i] == 1:
                if d[j][i - 1] + d[j][i + 1] == 1:
                    min_m = min(1, min_m)
                elif d[j][i - 1] == d[j][i + 1] == 1:
                    min_m = min(0, min_m)
            else:
                if d[j][i - 1] == d[j][i + 1] == 1:
                    min_m = min(1, min_m)
min_m = min(2, min_m)
print(min_m)

a = [str(i) for i in input().split()]
a.sort()
first = a[0]
second = a[1]
third = a[2]
firstnum = int(first[0])
secondnum = int(second[0])
thirdnum = int(third[0])
if(first == second):
	if(second == third):
		print(0)
	else:
		print(1)
elif(second == third):
	print(0)
elif(first[1] == second[1] and second[1] == third[1]):
	if(firstnum +1 == secondnum and secondnum + 1 == thirdnum):
		print(0)
	elif(firstnum + 1 == secondnum or firstnum+2 == secondnum):
		print(1)
	elif(secondnum + 1 == thirdnum or secondnum + 2 == thirdnum):
		print(1)
	else:
		print(2)
elif(first[1] == second[1] and firstnum + 1 == secondnum or firstnum+2 == secondnum):
	print(1)
elif(second[1] == third[1] and secondnum + 1 == thirdnum or secondnum+2 == thirdnum):
	print(1)
elif(first[1] == third[1] and (firstnum + 1 == thirdnum or firstnum + 2 == thirdnum)):
	print(1)
else:
	print(2)

import sys
import math
import bisect
import atexit
import io
import heapq
from collections import defaultdict, Counter
MOD = int(1e9+7)

# n = map(int, raw_input().split())
# input = map(int, raw_input().split())
def main():
    a, b, c = raw_input().split()
    d = defaultdict(list)
    num = []
    ans = 2
    for st in (a,b,c):
        nu, ch = st
        nu = int(nu)
        d[ch].append(int(nu))
        num.append(nu)
    num.sort()
    if num[0] == num[-1]-2:
        ans = 0
    if num[0] == num[1]-2 or num[1] == num[-1]-2 or num[0] == num[1]-1 or num[1] == num[2]-1:
        ans = min(ans, 1)
    for k, v in d.items():
        v.sort()
        if len(v) == 3:
            ans = 0
        elif len(v)==2:
            ans = min(ans, 1)
    print ans

main()

a, b, c = map(str, input().split())
a0, b0, c0 = int(a[0]), int(b[0]), int(c[0])
mx, mn = max(a0, b0, c0), min(a0, b0, c0)
if a == b == c or mx - mn == 2:
    print(0)
else:
    if abs(a0 - b0) == 1 or abs(a0 - b0) == 2 or abs(c0 - b0) == 1 or abs(c0 - b0) == 2 or abs(a0 - c0) == 1 or abs(a0 - c0) == 2:
        print(1)
    else:
        print(2)

a,b,c=raw_input().split()
if a==b and b==c:
    print 0 # all equal
elif a==b or b==c or a==c:
    print 1 # any two equal
elif a[1]==b[1]:
    if b[1]==c[1]: # all same cat
        if abs(int(a[0])-int(b[0]))<3 and abs(int(c[0])-int(b[0]))<3 and abs(int(a[0])-int(c[0]))<3:
            if 2*int(b[0])==int(a[0])+int(c[0]) and 2*int(c[0])==int(a[0])+int(b[0]) or 2*int(a[0])==int(c[0])+int(b[0]): # same cat and AP
                print 0
            else:
                print 1
        elif abs(int(a[0])-int(b[0]))<3 or abs(int(c[0])-int(b[0]))<3 or abs(int(a[0])-int(c[0]))<3:
            print 1
        else:
            print 2
    elif abs(int(a[0])-int(b[0]))<3: # only a and b same cat
        print 1
    else:
        print 2
elif c[1]==b[1]: # b and c same cat
    if abs(int(c[0])-int(b[0]))<3: # b and c consec
        print 1
    else:
        print 2 # b and c not consec
elif a[1]==c[1]:
    if abs(int(a[0])-int(c[0]))<3:
        print 1
    else:
        print 2
else:
    print 2

a  = input().split()
p = []
m = []
s = []
for i in a:
    n = int(i[0])
    if i[1]=='p':
        p.append(n)
    elif i[1]=='m':
        m.append(n)
    else:
        s.append(n)

for qq in (p,m,s):
    if len(qq)>2:
        sp = list(sorted(list(set(qq))))
        if len(sp)==1:
            print(0)
        elif len(sp)==2:
            print(1)
        else:
            if max(sp)-min(sp)==2:
                print(0)
            else:
                if sp[1]-sp[0]<3:
                    print(1)
                elif sp[2]-sp[1]<3:
                    print(1)
                else:
                    print(0)
        exit()
else:
    if len(p)==2:
        if abs(p[0]-p[1])<3:
            print(1)
        else:
            print(2)

    elif len(m)==2:
        if abs(m[0]-m[1])<3:
            print(1)
        else:
            print(2)

    elif len(s)==2:
        if abs(s[0]-s[1])<3:
            print(1)
        else:
            print(2)
    else:
        print(2)

p = input().split()
p = set(p)
ans = 2
for i1 in p:
    for i2 in p:
        if i1[1] == i2[1] and 1 <= int(i1[0]) - int(i2[0]) <= 2:
            ans -= 1
ans = min(ans, len(p) - 1)
print(max(0, ans))

d = {
    'm': 10,
    's': 20,
    'p': 30
}

a, b, c = list(sorted([int(i[0]) + d[i[1]] for i in input().split(' ')]))

if (a == b and b == c) or (a == b - 1 and b == c - 1):
    print(0)
    exit()
if a == b - 1 or b == c - 1 or a == b or b == c:
    print(1)
    exit()
print(2)

def f(a, b, c):
    if a[0] > b[0]:
        a, b = b, a
    if abs(int(a[0]) - int(b[0])) == 1 and a[1] == b[1]:
        if a[1] == c[1] and abs(int(c[0]) - int(b[0])) == 1:
            return 0
        else:
            return 1
    if abs(int(a[0]) - int(b[0])) == 2 and a[1] == b[1]:
        return 1
    return 2

a, b, c = input().split()
s1 = set()
s1.add(a)
s1.add(b)
s1.add(c)
c1 = len(s1) - 1
print(min(c1, f(a, b, c), f(a, c, b), f(b, c, a)))

a, b, c = map(str, input().split())
a0, b0, c0 = int(a[0]), int(b[0]), int(c[0])
mx, mn = max(a0, b0, c0), min(a0, b0, c0)
if a == b == c or mx - mn == 2:
    print(0)
else:
    if abs(a0 - b0) <= 2 or abs(c0 - b0) <= 2 or abs(a0 - c0) <= 2:
        print(1)
    else:
        print(2)

t=list(map(str,input().split()))
t.sort()

s=0
ins=0
ist=0
m=0
inm=0
imt=0
p=0
inp=0
ipt=0
count=1
shout=1
prev=0
last=1
pout=1
one=0
for i in range(1,len(t)):
	prev=i-1
	if(t[i][1]==t[prev][1]):
		if(int(t[i][0])==int(t[prev][0])):
			last=last+1
		elif((int(t[i][0])==(int(t[prev][0])+1)) ):
			count=count+1
		else:
			if((int(t[i][0])==(int(t[prev][0])+2))):
				one=1

	else:
		shout=max(count,shout)
		pout=max(last,pout)
		count=1
		last=1
if(one==0):
	print(min(3-shout,3-count,3-pout,3-last))
else:
	print(min(3-shout,3-count,3-pout,3-last,1))

# target Specialist

"""
Beautiful is better than ugly.
    Explicit is better than implicit.
Simple is better than complex.
    Complex is better than complicated.
Flat is better than nested.
    Sparse is better than dense.

    * Readability counts *

 // Author : raj1307 - Raj Singh
 // Date   : 12.07.19

"""

from __future__ import division, print_function

import os,sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def ii(): return int(input())
def si(): return input()
def mi(): return map(str,input().strip().split(" "))
def li(): return list(mi())

def dmain():
    sys.setrecursionlimit(100000000)
    threading.stack_size(40960000)
    thread = threading.Thread(target=main)
    thread.start()

#from collections import deque, Counter, OrderedDict,defaultdict
#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
#from math import ceil,floor,log,sqrt,factorial,pow,pi
#from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
#from decimal import *,threading
#from itertools import permutations

abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod,MOD=1000000007,998244353
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def getKey(item): return item[0]
def sort2(l):return sorted(l, key=getKey)
def d2(n,m,num):return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo (x): return (x and (not(x & (x - 1))) )
def decimalToBinary(n): return bin(n).replace("0b","")
def ntl(n):return [int(i) for i in str(n)]

def powerMod(x,y,p):
    res = 1
    x %= p
    while y > 0:
        if y&1:
            res = (res*x)%p
        y = y>>1
        x = (x*x)%p1
    return res

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

def read():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')

def main():

    #for _ in range(ii()):

    a,b,c=mi()

    if a==b and b==c:
        print(0)

    elif (a==b and b!=c) or (a==c and b!=c) or (c==b and a!=c):
        print(1)

    else:

        l=[[int(a[0]),a[1]],[int(b[0]),b[1]],[int(c[0]),c[1]]]

        l=sort2(l)

        if l[1][0]==l[0][0]+1 and l[2][0]==l[1][0]+1 and a[1]==b[1] and c[1]==b[1]:
                print(0)

        elif (l[1][0]==l[0][0]+1  and l[1][1]==l[0][1]) or (l[2][0]==l[1][0]+1  and l[2][1]==l[1][1]) or (l[2][0]==l[0][0]+2  and l[2][1]==l[0][1]) or (l[1][0]==l[0][0]+2  and l[1][1]==l[0][1]) or (l[2][0]==l[1][0]+2  and l[2][1]==l[1][1]):
            print(1)

        else:
            print(2)

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    #read()
    main()
    #dmain()

# Comment Read()

#Tokitsukaze and Mahjong
DEBUG = False

def debug(to_print_args):
    if not DEBUG:
        return
    for arg in to_print_args:
        print(arg,end='')
    print()

# def shuntsu(num1,num2,num3,a1,a2,a3):
#     if num1+1=num2 and num1+2=num3:
#         if a1=a2 and a2=a3:
#             return True;
#         else

a=input().split()

strings=[a[0][1],a[1][1],a[2][1]];
numbers=[a[0][0],a[1][0],a[2][0]];

numbers=list(map(int,numbers));

if strings[0]==strings[1] and strings[1]==strings[2]:
    if numbers[0]==numbers[1] and numbers[1]==numbers[2]:
        print(0);
    elif abs(numbers[0]-numbers[1])==1  and abs(numbers[2]-numbers[1])==1 and abs(numbers[2]-numbers[0])==2:
        print(0);
    elif abs(numbers[0]-numbers[1])==1  and abs(numbers[2]-numbers[1])==1 and abs(numbers[2]-numbers[0])==1:
        print(1);
    elif abs(numbers[0]-numbers[1])==1 or abs(numbers[1]-numbers[2])==1 or abs(numbers[0]-numbers[2])==1:
        print(1);
    elif numbers[0]==numbers[1] or numbers[1]==numbers[2] or numbers[0]==numbers[2]:
        print(1);
    elif abs(numbers[0]-numbers[1])==2 or abs(numbers[1]-numbers[2])==2 or abs(numbers[0]-numbers[2])==2:
        print(1);
    else:
        print(2);
elif strings[0]==strings[1]:
    if numbers[0]==numbers[1]:
        print(1);
    elif abs(numbers[0]-numbers[1])==1:
        print(1);
    elif abs(numbers[0]-numbers[1])==2:
        print(1);
    else:
        print(2);

elif strings[2]==strings[1]:
    if numbers[2]==numbers[1]:
        print(1);
    elif abs(numbers[2]-numbers[1])==1:
        print(1);
    elif abs(numbers[2]-numbers[1])==2:
        print(1);
    else:
        print(2);

elif strings[0]==strings[2]:
    if numbers[0]==numbers[2]:
        print(1);
    elif abs(numbers[0]-numbers[2])==1:
        print(1);
    elif abs(numbers[0]-numbers[2])==2:
        print(1);
    else:
        print(2);

else:
    print(2);

b=list(input().split())
a=b[0]
c=b[1]
d=b[2]
p=[int(a[0]),int(c[0]),int(d[0])]
p.sort()
if a[1]==c[1]:
    if a[1]==d[1]:
        k=p[1]-p[0]
        q=p[2]-p[1]
        if k==0 and q==0:
            print(0)
        elif k==0 or q==0:
            print(1)
        elif k==1 and q==1:
            print(0)
        elif k==1 or q==1:
            print(1)
        else:
            print(2)
    else:
        if int(a[0])==int(c[0]):
            print(1)
        elif abs(int(a[0])-int(c[0]))==1:
            print(1)
        else:
            print(2)
else:
    if c[1]==d[1]:
        if int(c[0]) == int(d[0]):
            print(1)
        elif abs(int(c[0]) - int(d[0])) == 1:
            print(1)
        else:
            print(2)
    elif a[1]==d[1]:
        if int(a[0]) == int(d[0]):
            print(1)
        elif abs(int(a[0]) - int(d[0])) == 1:
            print(1)
        else:
            print(2)
    else:
        print(2)

a=list(input().split())
ar1=[]
ar2=[]
for i in a:
    ar1.append(int(i[0]))
    ar2.append(i[1])
s=set()
for i in range(3):
    for j in range(i,3):
        if ar2[i]==ar2[j]:
            s.add(i)
            s.add(j)
if len(s)==0:
    print(2)
elif len(s)==2:
    i1=s.pop()
    i2=s.pop()
    if abs(ar1[i1]-ar1[i2])<=1:
        print(1)
    else:
        print(2)
else:
    ar1.sort()
    d1=ar1[1]-ar1[0]
    d2=ar1[2]-ar1[1]
    if d1==0:
        if d2==0:
            print(0)
        else:
            print(1)
    elif d1==1:
        if d2==1:
            print(0)
        else:
            print(1)
    else:
        if d2==0 or d2==1:
            print(1)
        else:
            print(2)

"""
NTC here
"""
from sys import setcheckinterval, stdin
setcheckinterval(1000)

# print("Case #{}: {} {}".format(i, n + m, n * m))

iin = lambda: int(stdin.readline())
lin = lambda: list(map(int, stdin.readline().split()))

def check1(a):
    n=len(a)
    ans=1
    for i in range(n):
        ch=1
        j=i+1
        while j<n:
            if a[j]==a[j-1]+1:
                ch+=1
            else:
                break
            j+=1
        ans=max(ans,ch)
    return 3-ans

def check2(a):
    d={}
    for i in a:
        try:
            d[i]+=1
        except:
            d[i]=1
    return 3-max(d.values()) if d else 3

s=input().split()
a1=[];a2=[];a3=[]

for i in s:
    if i[1]=='m':
        a1.append(int(i[0]))
    elif i[1]=='p':
        a2.append(int(i[0]))
    elif i[1]=='s':
        a3.append(int(i[0]))
a1.sort()
a2.sort()
a3.sort()

ans=min(check1(a1),check2(a1),check1(a2),check2(a2),check1(a3),check2(a3))
print(ans)

a, b, c = sorted(input().split(), key = lambda x: int(x[0]))

if a == b == c: print(0)
elif a[1] == b[1] == c[1] and int(a[0])+2 == int(b[0])+1 == int(c[0]): print(0)
elif a == b or b == c or c == a: print(1)
elif a[1] == b[1] and int(a[0])+2 == int(b[0])+1: print(1)
elif b[1] == c[1] and int(b[0])+2 == int(c[0])+1: print(1)
else: print(2)

# int(input())
# [int(s) for s in input().split()]
# input()

def solve():
    m = [s for s in input().split()]
    d = {"m": [], "p": [], "s": []}

    ans = float("inf")

    for s in m:
        d[s[1]].append(int(s[0]))

    for s in d:
        if len(d[s]) == 1:
            ans = min(ans, 2)
        elif len(d[s]) == 2:
            d[s] = sorted(d[s])
            if d[s][0] == d[s][1]:
                ans = min(ans, 1)
            elif d[s][0]+1 == d[s][1] or d[s][0]+2 == d[s][1]:
                ans = min(ans, 1)
        elif len(d[s]) == 3:
            d[s] = sorted(d[s])
            if d[s][0] == d[s][1]:
                if d[s][1] == d[s][2]:
                    ans = min(ans, 0)
                else:
                    ans = min(ans, 1)
            else:
                if d[s][0]+1 == d[s][1]:
                    if d[s][1] + 1 == d[s][2]:
                        ans = min(ans, 0)
                    else:
                        ans = min(ans, 1)
                elif d[s][0]+2 == d[s][1]:
                    ans = min(ans, 1)

    print(ans)

if __name__ == "__main__":
    solve()

a,b,c = input().split();
import sys;
x = int(a[0]);
y = int(b[0]);
z = int(c[0]);
if(a==b==c):
    print(0);
    sys.exit();
else:
    arr = [x,y,z];
    arr.sort();
    if(a[1]==b[1]==c[1]):
        if((y-x)==1 and (z-y)==1):
            print(0);
            sys.exit();
        else:
            print(2);
            sys.exit();

    if(a[1]==b[1] or b[1]==c[1] or c[1]==a[1]):

        if(a[1]==b[1]):
            if(abs(x-y)==1 or abs(x-y)==2):
                print(1);
                sys.exit();

            else:
                print(2);
                sys.exit();
        if(b[1]==c[1]):
            if(abs(y-z)==1 or abs(y-z)==2):
                print(1);
                sys.exit();
            else:
                print(2);
                sys.exit();
        if(a[1]==c[1]):
            if(abs(x-z)==1 or abs(x-z)==2):
                print(1);
                sys.exit();
            else:
                print(2);
                sys.exit();
        else:
            print(2);
            sys.exit();

    else:
        print(2);
        sys.exit();

from sys import stdin
from math import fabs

def prob(x,y,z):
    acu = 0

    if fabs(max(int(x[0]),int(y[0]),int(z[0])) - min(int(x[0]),int(y[0]),int(z[0]))) == 2 and (int(x[0]) + int(y[0]) + int(z[0])) % 3 == 0 :
        return True
    return False

def need(x,y,z):
    if x == y and y == z:
        return 0
    elif (x == y and y !=z) or (x == z and z != y) or (z == y and y != x):
        return 1
    elif x[1] == y[1] == y[1]:
        if prob(x,y,z):
            return 0
        elif (fabs(int(x[0])-int(y[0]) == 1) or (fabs(int(x[0])-int(z[0]))) == 1) or (abs(int(z[0])-int(y[0])) == 1):
            return 1
        else:
            return 2
    elif (x[1] == y[1] != z[1]):
        if (fabs(int(x[0])-int(y[0]))) == 1:
            return 1
        else:
            return 2
    elif x[1] == z[1] != y[1]:
        if (fabs(int(x[0])-int(z[0]))) == 1:
            return 1
        else:
            return 2
    elif z[1] == y[1] != x[1]:
        if (fabs(int(y[0])-int(z[0]))) == 1:
            return 1
        else:
            return 2
    else:
        return 2

x,y,z = stdin.readline().split()

print(need(x,y,z))

# int(input())
# [int(s) for s in input().split()]
# input()

def solve():
    m = [s for s in input().split()]
    d = {"m": [], "p": [], "s": []}

    ans = float("inf")

    for s in m:
        d[s[1]].append(int(s[0]))

    for s in d:
        if len(d[s]) == 1:
            ans = min(ans, 2)
        elif len(d[s]) == 2:
            d[s] = sorted(d[s])
            if d[s][0] == d[s][1]:
                ans = min(ans, 1)
            elif d[s][0]+1 == d[s][1] or d[s][0]+2 == d[s][1]:
                ans = min(ans, 1)
        elif len(d[s]) == 3:
            d[s] = sorted(d[s])
            if d[s][0] == d[s][1]:
                if d[s][1] == d[s][2]:
                    ans = min(ans, 0)
                else:
                    ans = min(ans, 1)
            else:
                if d[s][0]+1 == d[s][1]:
                    if d[s][1] + 1 == d[s][2]:
                        ans = min(ans, 0)
                    else:
                        ans = min(ans, 1)
    print(ans)
    print(d)

if __name__ == "__main__":
    solve()

#Tokitsukaze and Mahjong
DEBUG = False

def debug(to_print_args):
    if not DEBUG:
        return
    for arg in to_print_args:
        print(arg,end='')
    print()

# def shuntsu(num1,num2,num3,a1,a2,a3):
#     if num1+1=num2 and num1+2=num3:
#         if a1=a2 and a2=a3:
#             return True;
#         else

a=input().split()

strings=[a[0][1],a[1][1],a[2][1]];
numbers=[a[0][0],a[1][0],a[2][0]];

numbers=list(map(int,numbers));

if strings[0]==strings[1] and strings[1]==strings[2]:
    if numbers[0]==numbers[1] and numbers[1]==numbers[2]:
        print(0);
    elif abs(numbers[0]-numbers[1])==1  and abs(numbers[2]-numbers[1])==1:
        print(0);
    elif abs(numbers[0]-numbers[1])==1 or abs(numbers[1]-numbers[2])==1 or abs(numbers[0]-numbers[2])==1:
        print(1);
    elif numbers[0]==numbers[1] or numbers[1]==numbers[2] or numbers[0]==numbers[2]:
        print(1);
    elif abs(numbers[0]-numbers[1])==2 or abs(numbers[1]-numbers[2])==2 or abs(numbers[0]-numbers[2])==2:
        print(1);

elif strings[0]==strings[1]:
    if numbers[0]==numbers[1]:
        print(1);
    elif abs(numbers[0]-numbers[1])==1:
        print(1);

elif strings[2]==strings[1]:
    if numbers[2]==numbers[1]:
        print(1);
    elif abs(numbers[2]-numbers[1])==1:
        print(1);

elif strings[0]==strings[2]:
    if numbers[0]==numbers[2]:
        print(1);
    elif abs(numbers[0]-numbers[2])==1:
        print(1);

else:
    print(2);

tl=list(map(str,input().split()))
n1=tl[0][0]
n2=tl[1][0]
n3=tl[2][0]
s1=tl[0][1]
s2=tl[1][1]
s3=tl[2][1]
nl=[int(n1),int(n2),int(n3)]
sl=[s1,s2,s3]
#print(nl)
#print(sl)
if len(set(sl))==3:
    print(2)
elif len(set(sl))==1:
    if len(set(nl))==1:
        print(0)
    elif len(set(nl))==2:
        print(1)
    else:
        tmnl=sorted(nl)
        if tmnl[1]==tmnl[0]+1 and tmnl[2]==tmnl[1]+1:
            print(0)
        elif tmnl[1]==tmnl[0]+1 or tmnl[2]==tmnl[1]+1 :
            print(1)
        else:
            print(2)
else:
    if sl[0]==sl[1]:
        if nl[0]==nl[1]:
            print(1)
        elif abs(nl[0]-nl[1])==1:
            print(1)
        else:
            print(0)
    elif sl[1]==sl[2]:
        if nl[1]==nl[2]:
            print(1)
        elif abs(nl[1]-nl[2])==1:
            print(1)
        else:
            print(0)
    else:
        if nl[0]==nl[2]:
            print(1)
        elif abs(nl[0]-nl[2])==1:
            print(1)
        else:
            print(0)

a = list(input().split())

k = dict()
mk = 0
mki = ""
s = 0

for e in a:
	if e not in k:
		k[e] = 0
	k[e] += 1

	if k[e] > mk:
		mk = k[e]
		mki = e

if mk >= 3:
	print(0)
	exit(0)

for e in a:
	temp = 1
	num = int(e[:1])
	t = e[1:]
	if (str(num + 1) + t) in k:
		temp += 1
	if (str(num - 1) + t) in k:
		temp += 1

	if temp > s:
		s = temp

if s > mk:
	print(3 - s)
else:
	print(3 - mk)

arr = list(map(lambda el: [int(el[0]), el[1]], input().split()))

sortt = sorted(arr, key=lambda el: el[0])

result = 2

for i in range(3):
    cnt1 = 2
    cnt2 = 2
    base = sortt[i][0]
    for y in range(i+1, 3):
        if sortt[i][1] == sortt[y][1]:
            if sortt[i][0] == sortt[y][0]:
                cnt1 -= 1
            elif sortt[y][0] == base + 1:
                cnt2 -= 1
            elif sortt[y][0] == base + 2:
                cnt2 = 1
            base = sortt[y][0]
        result = min(result, cnt1, cnt2)

print(result)

import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

lis = [x for x in input().split()]
res = 2
s = set(tuple(lis))
if len(s) == 1:
    print(0)
elif len(s) == 2:
    print(1)
else:
    res = 2
    for c in lis:
        x = int(c[0]) + 1
        ch = str(x) + c[1]
        if ch in s:
            res -= 1
    print(res)

a, b, c = input().split()

numbers = [int(a[0]), int(b[0]), int(c[0])]
letters = [a[1], b[1], c[1]]
if (a == b == c):
	print(0)

else:
	order = sorted(numbers)
	flag = 0
	for i in range(2):
		diff = order[i + 1] - order[i]
		if (diff != 1):
			flag = 1
			break
	if(flag == 0 and letters[0] == letters[1] == letters[2]):
		print(0)

	else:

		#print(letters)
		p = letters.count("p")
		m = letters.count("m")
		s = letters.count("s")
		#print(m, p, s)
		if(p == 1 and m == 1 and s == 1):#each of diff type
			print(2)

		else:
			if (m == 3 or p == 3 or s == 3):
				order = sorted(numbers)
				diff = []
				for i in range(2):
					diff.append(order[i + 1] - order[i])
				if(1 in diff or 2 in diff):
					print(1)
				else:
					print(2)
			else:
				#1, 2
				if (letters[0] == letters[1]):
					twos = [numbers[0], numbers[1]]
				elif(letters[0] == letters[2]):
					twos = [numbers[0], numbers[2]]
				else:
					twos = [numbers[1], numbers[2]]

				if (abs(twos[1] - twos[0]) == 1 or abs(twos[1] - twos[0]) == 2):
					print(1)
				else:
					print(2)

d = {
    'm': 10,
    's': 20,
    'p': 30
}

a, b, c = list(sorted([int(i[0]) + d[i[1]] for i in input().split(' ')]))

if (a == b and b == c) or (a == b - 1 and b == c - 1):
    print(0)
    exit()
if a == b - 1 or b == c - 1 or a == b or b == c:
    print(1)
    exit()
print(2)

data = input().split()
data.sort()

dic = {"s":[], "m":[], "p":[]}
for d in data:
    dic[d[1]].append(d)
#mx = max([len(l) for l in dic.values()])
vals = list(dic.values())
vals.sort(key=lambda a: len(a))
lis = vals[-1]
lis.sort()
if len(lis) == 3:
    if lis[0] == lis[1]:
        if lis[1] == lis[2]:
            print(0)
        else:
            print(1)
    else:
        if lis[1] == lis[2]:
            print(1)
        else:
            ns = [int(a[0]) for a in lis]
            if ns[0] + 1 == ns[1]:
                if ns[1] + 1 == ns[2]:
                    print(0)
                else:
                    print(1)
            else:
                if ns[1] + 1 == ns[2]:
                    print(1)
                else:
                    print(2)

elif len(lis) == 2:
    if lis[0] == lis[1] or int(lis[0][0]) + 1 == int(lis[1][0]):
        print(1)
    else:
        print(2)

else:
    print(2)

# if data[0] == data[1]:
#     pass
# else:
#     if data[1] == data[2]:
#         print(1)
#     else

# Coding credits Moaz Adnan
my_String = list(raw_input().split())

my_String.sort()
num = []
letter =[]
for item in my_String:
	letter.append(item[1])
	num.append(int(item[0]))

if len(set(my_String)) == 1:
	print (0)
elif len(set(letter)) <= 2:
	if num[0] == num[1] or num[1] == num[2] or num[0] == num[2]:
		print(1)
	elif (num[2] - num[0]) - (num[2] - num[1] )<= 2 :
		if num[2] - num[1] == 1:
			print(0)
		elif letter[0] == letter [1]:
			print(1)
		else:
			print(2)
	else:
		print(2)
else:
	print(2)

m=[x for x in input().split()]
tiles=[[0 for i in range(9)] for j in range(3)]
for i in range(len(m)):
    g=int(m[i][0])-1
    h=(m[i][1])
    if h=="m":
        tiles[0][g]+=1
    elif h=="p":
        tiles[1][g]+=1
    else:
        tiles[2][g]+=1
if m[0]==m[1] and m[1]==m[2]:
    print(0)
elif m[0]==m[1]:
    print(1)
elif m[0]==m[2]:
    print(1)
elif m[1]==m[2]:
    print(1)
else:
    n=False
    for i in range(3):
        for j in range(9):
            if tiles[i][j]!=0:
                if j!=8 and tiles[i][j+1]!=0:
                    if j!=7 and tiles[i][j+2]!=0:
                        print(0)
                        n=True
                        break
                    else:
                        print(1)
                        n=True
                        break
    if n==False:
        print(2)

d={'m':10,'p':20,'s':30}

#men=> kou or shu
x,y,z=[int(x[0])+d[x[1]] for x in sorted(input().split())]

#kou and sust
if (x==y and y==z) or (x==y-1 and y==z-1):
    print('0')
    #exit()
elif x==y or y==z or x==z or x==y-1 or y==z-1 or x==y-2 or y==z-2 :
    print('1')
    #exit()
else:
    print('2')

l = list(input().split())
d = {}
for i in l:
    if i[1] not in d:d[i[1]] = [int(i[0])]
    else:
        d[i[1]].append(int(i[0]))
best = []
for i in d:
    if len(d[i]) > len(best):
        best = d[i]
if len(best)==1:print(2)
elif len(best)==3 and len(set(best))==1:print(0)
else:
    m = min(best)
    if m+1 in best:
        if m+2 in best:print(0)
        else:print(1)
    else:print(2)

a,b,c = [s for s in input().split()]
shuts = set()
koutsu = set()

if a == b:
    koutsu.add(a)
    koutsu.add(b)
    if a == c:
        koutsu.add(c)
elif a == c:
    koutsu.add(a)
    koutsu.add(c)

elif b == c:
    koutsu.add(b)
    koutsu.add(c)

elif ((int(a[0])==int(b[0])+1 or int(a[0]) == int(b[0])-1) or (int(b[0]) == int(a[0])+1 or int(b[0]) == int(a[0])-1)) and a[1]==b[1]:
    shuts.add(a)
    shuts.add(b)
    if ((int(b[0])==int(c[0])+1 or int(b[0]) == int(c[0])-1) or (int(c[0]) == int(b[0])+1 or int(c[0]) == int(b[0])-1)) and c[1]==b[1]:
        shuts.add(c)
elif ((int(b[0])==int(c[0])+1 or int(b[0]) == int(c[0])-1) or (int(c[0]) == int(b[0])+1 or int(c[0]) == int(b[0])-1)) and c[1]==b[1]:
    shuts.add(b)
    shuts.add(c)

elif ((int(c[0])==int(a[0])+1 or int(c[0]) == int(a[0])-1) or (int(a[0]) == int(c[0])+1 or int(a[0]) == int(c[0])-1)) and a[1]==c[1]:
    shuts.add(a)
    shuts.add(c)

if ((int(a[0])==int(b[0])+2) or (int(b[0])==int(a[0])+2)) and a[1]==b[1]:
    shuts.add(a)
    shuts.add(b)
elif ((int(b[0])==int(c[0])+2) or (int(c[0])==int(b[0])+2)) and b[1]==c[1]:
    shuts.add(b)
    shuts.add(c)
elif ((int(a[0])==int(c[0])+2) or (int(c[0])==int(a[0])+2)) and c[1]==a[1]:
    shuts.add(a)
    shuts.add(c)

if max(len(shuts), len(koutsu))==0:
    print(2)
else:
    print(3-max(len(shuts), len(koutsu)))

h = [hi for hi in raw_input().split(" ")]
suits = ['m','p','s']
k23 = []
kf = []
s23 = []
sf = []
a = 1
b = 9
for i in range(a,b+1):
	# print i,i,i
	for suit in suits:
		k23 += [[str(i)+suit,str(i)+suit]]
		kf += [[str(i)+suit,str(i)+suit,str(i)+suit]]
for i in range(a,b):
	for suit in suits:
		s23 += [[str(i)+suit,str(i+1)+suit]]
for i in range(a,b-1):
	for suit in suits:
		sf += [[str(i)+suit,str(i+1)+suit,str(i+2)+suit]]
h012 = [h[0]]+[h[1]]+[h[2]]
h021 = [h[0]]+[h[2]]+[h[1]]
h102 = [h[1]]+[h[0]]+[h[2]]
h120 = [h[1]]+[h[2]]+[h[0]]
h201 = [h[2]]+[h[0]]+[h[1]]
h210 = [h[2]]+[h[1]]+[h[0]]

h01 = [h[0]]+[h[1]]
h02 = [h[0]]+[h[2]]
h10 = [h[1]]+[h[0]]
h12 = [h[1]]+[h[2]]
h20 = [h[2]]+[h[0]]
h21 = [h[2]]+[h[1]]

if h012 in kf or h012 in sf:
	print 0
elif h021 in kf or h021 in sf:
	print 0
elif h102 in kf or h102 in sf:
	print 0
elif h120 in kf or h120 in sf:
	print 0
elif h201 in kf or h201 in sf:
	print 0
elif h210 in kf or h210 in sf:
	print 0
elif h01 in k23 or h01 in s23:
	print 1
elif h02 in k23 or h02 in s23:
	print 1
elif h10 in k23 or h10 in s23:
	print 1
elif h12 in k23 or h12 in s23:
	print 1
elif h20 in k23 or h20 in s23:
	print 1
elif h21 in k23 or h21 in s23:
	print 1
else:
	print 2

my_String = list(raw_input().split())

my_String.sort()
num = []
letter =[]
for item in my_String:
	letter.append(item[1])
	num.append(int(item[0]))

if len(set(my_String)) == 1:
	print (0)
elif len(set(letter)) <= 2:
	if num[0] == num[1] or num[1] == num[2] or num[0] == num[2]:
		print(1)
	elif (num[2] - num[0]) - (num[2] - num[1] )<= 2 :
		if num[2] - num[1] == 1 and letter[2] == letter[1] and letter[2] == letter[0]:
			print(0)
		elif abs (num[0] - num[1]) <= 2 or abs(num[1] - num[2]) <=2 or abs(num[0] - num[2])<= 2:
			print(1)
		else:
			print(2)
	else:
		print(2)
else:
	print(2)

# Main

data = [x for x in raw_input().split(" ")]
sol = None

if len(set(data)) == 1:
	sol = 0

elif data[0][1] == data[1][1] and data[0][1] == data[2][1]:
	nums = [int(data[0][0]), int(data[1][0]), int(data[2][0])]
	nums.sort()
	if nums[0] == nums[1] - 1:
		if nums[1] == nums[2] - 1:
			sol = 0
		else:
			sol = 1
	else:
		if nums[1] == nums[2] - 1:
			sol = 1

elif len(set(data)) == 2:
	if sol != 0:
		sol = 1

# I think this entire block is redundants since I handled it in the
# check above... That said, I don't think it'll hurt - worst case if
# I'm right, it'll just fire down this branch in the case of a 2

if sol == None:
	if data[0][1] == data[1][1]:
		if abs(int(data[0][0]) - int(data[1][0])) == 1:
			# they're off by one and we only need one more piece
			sol = 1

	if data[0][1] == data[2][1]:
		if abs(int(data[0][0]) - int(data[2][0])) == 1:
			# they're off by one and we only need one more piece
			sol = 1

	if data[1][1] == data[2][1]:
		if abs(int(data[1][0]) - int(data[2][0])) == 1:
			# they're off by one and we only need one more piece
			sol = 1

if sol == None:
	sol = 2

print sol

def diff(a,b):
    a=int(a)
    b=int(b)
    if a>b:
        return(a-b)
    else:
        return(b-a)
x,y,z=input().split()
if x==y and y==z:
    p=0
elif x==y or y==z or x==z:
    p=1
else:
    l=[x[1]]
    if y[1] not in l:
        l.append(y[1])
    if z[1] not in l:
        l.append(z[1])
    if len(l)==3:
        p=2
    elif len(l)==2:
        if x[1]==y[1]:
            t=(x,y)
        elif x[1]==z[1]:
            t=(x,z)
        else:
            t=(y,z)
        if diff(t[0][0],t[1][0])==1:
            p=1
        else:
            p=2
    else:
        q=0
        if diff(x[0],y[0])==1:
            q+=1
        if diff(y[0],z[0])==1:
            q+=1
        if diff(x[0],z[0])==1:
            q+=1
        if q==2:
            p=0
        elif q==1:
            p=1
        else:
            p=2
print(p)

def main():
    list_str = input().split()
    list_str.sort()

    """ p = ['3p', '5s', '5s'] (after sort)
    sorted by decimal its mean either ['3p','5p'] or ['5p','5p']
    near to koutsu, or whole string koutsu
    either 1,2,3.... 0 is impossible"""
    # if koutsu 2 or 3 then cannot be shuntsu
    if len(set(list_str)) == 1:  # all equal
        print(0)
        return 0# if koutsu 2 or 3 then cannot be shuntsu

    elif len(set(list_str)) == 2:  # either one equal
        print(1)
        return 0# if koutsu 2 or 3 then cannot be shuntsu

    ###############################################
    shuntsu_count = 0
    """
    1s,5m,3s  => after sort 1s,3s,5m
    1s,5m,2s  => after sort 1s,2s,5m
    1s,2m,2s  => after sort 1s,2m,2s

    so i guess better to digits

    1,2,2
    s,m,s
    """
    num = []
    lstr = []
    for e in list_str:
        num.append(int(e[0]))
        lstr.append(e[1])

    # Already sorted so smallest to largest, so need of abs
    if lstr[0] == lstr[1] and (num[0] - num[1])<=2:
        shuntsu_count += 1

    if lstr[0] == lstr[2] and (num[0] - num[2])<=2:
        shuntsu_count += 1

    if lstr[1] == lstr[2] and (num[1] - num[2])<=2:
        shuntsu_count += 1

    if shuntsu_count >= 3:
        print(0)
    elif shuntsu_count == 0:
        # atleast Count one of kind already
        print(2)
    else:
        print(1)

main()

t=raw_input().split()
t.sort()
k = {}

def get_draws():
	for x in t:
		if not x[-1] in k:
			k[x[-1]]=[]
		k[x[-1]].append(int(x[:-1]))
	for i in k.keys():
		length=len(k[i])
		all_same = k[i].count(k[i][0])==length
		if all_same:
			if (length==3):
				print '0'
				return
			elif length==2:
				print '1'
				return
		else:
			diff_list = []
			for x, y in zip(k[i][0::], k[i][1::]):
				diff_list.append(y-x)
			if diff_list.count(diff_list[0]) == len(diff_list) and diff_list[0]<=2:
				if length==3:
					print '0'
					return
				elif length==2:
					print '1'
					return
	print '2'
	return
get_draws()

n=list(map(str,input().split(" ")))

d=dict()

mp = {"m":0 , "p":1 , "s":2}

l=[0]*10
arr = [l,l,l]

maxi=0

for i in n:
	# print(i)
	if (i in d.keys()):
		d[i]+=1
		maxi = max(maxi,d[i])

	else:
		d[i]=1
		maxi = max(maxi,d[i])

	arr[mp[i[1]]][int(i[0])] = 1

if(maxi>=3):
	print(0)
else:
	temp2 = 0
	for i in range(3):
		ansi=0
		for j in range(10):
			if(arr[i][j] ==0):
				ansi=0
			if(arr[i][j]==1):
				ansi+=arr[i][j]
				temp2=max(ansi,temp2)

	finalAns = min(3-maxi, 3-temp2)
	print(finalAns)

l = list(input().split())
d = {}
for i in l:
    if i[1] not in d:d[i[1]] = [int(i[0])]
    else:
        d[i[1]].append(int(i[0]))
best = []
for i in d:
    if len(d[i]) > len(best):
        best = d[i]
if len(best)==1:print(2)
elif len(set(best))==1:
    print(3-len(best))
else:
    m = min(best)
    if m+1 in best:
        if m+2 in best:print(0)
        else:print(1)
    else:print(2)

t=list(map(str,input().split()))
t.sort()

s=0
ins=0
ist=0
m=0
inm=0
imt=0
p=0
inp=0
ipt=0
count=1
shout=1
prev=0
for i in range(1,len(t)):
	prev=i-1
	if(t[i][1]==t[prev][1]):
		if(int(t[i][0])==int(t[prev][0])):
			count=count+1
		elif((int(t[i][0])==(int(t[prev][0])+1))):
			count=count+1
	else:
		shout=max(count,shout)
		count=1
print(min(3-shout,3-count))

a, b, c = map(str, input().split())
a0, b0, c0 = int(a[0]), int(b[0]), int(c[0])
mx, mn = max(a0, b0, c0), min(a0, b0, c0)
if a == b == c or mx - mn == 2:
    print(0)
else:
    if abs(a0 - b0) <= 2 or abs(c0 - b0) <= 2 or abs(a0 - c0) <= 2:
        print(1)
    else:
        print(2)