Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from $1$ to $9$). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, $\ldots$, 9m, 1p, 2p, $\ldots$, 9p, 1s, 2s, $\ldots$, 9s.

In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.

Do you know the minimum number of extra suited tiles she needs to draw so that she can win?

Here are some useful definitions in this game:  A mentsu, also known as meld, is formed by a koutsu or a shuntsu;  A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;  A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. 

Some examples:   [2m, 3p, 2s, 4m, 1s, 2s, 4s] — it contains no koutsu or shuntsu, so it includes no mentsu;  [4s, 3m, 3p, 4s, 5p, 4s, 5p] — it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;  [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] — it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. 

Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.


-----Input-----

The only line contains three strings — the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from $1$ to $9$ and the second character is m, p or s.


-----Output-----

Print a single integer — the minimum number of extra suited tiles she needs to draw.


-----Examples-----
Input
1s 2s 3s

Output
0

Input
9m 9m 9m

Output
0

Input
3p 9m 2p

Output
1



-----Note-----

In the first example, Tokitsukaze already has a shuntsu.

In the second example, Tokitsukaze already has a koutsu.

In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile — 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].

Source: codeforces | Difficulty: EASY
Tags: Implementation

Complete search


Solutions:
def cm(a, b, c):
	if a[1] == b[1] == c[1]:
		if a[0] == b[0] == c[0]:
			return True
		m = [int(a[0]), int(b[0]), int(c[0])]
		m.sort()
		if m[2] - m[1] == 1 and m[1] - m[0] == 1:
			return True
	return False
(a, b, c) = input().split()
ans = False
if cm(a, b, c):
	print(0)
	ans = True
elif not ans:
	p = []
	for i in range(10):
		for j in ['m', 'p', 's']:
			p.append(str(i) + j)
	for i in p:
		if cm(i, b, c):
			ans = True
			break
		if cm(i, a, b):
			ans = True
			break
		if cm(i, a, c):
			ans = True
	if ans:
		print(1)
if not ans:
	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)
		elif k == 2 or q == 2:
			print(1)
		else:
			print(2)
	elif int(a[0]) == int(c[0]):
		print(1)
	elif abs(int(a[0]) - int(c[0])) <= 2:
		print(1)
	else:
		print(2)
elif 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)


l = input().split()
suit = ['m', 'p', 's']
from collections import defaultdict
cnt = defaultdict(lambda : 0)
for i in range(3):
	cnt[l[i]] += 1
mini = 10
for i in suit:
	for j in range(1, 10):
		if j + 2 <= 9:
			cn = 0
			for k in range(3):
				cn += int('{}{}'.format(j + k, i) not in cnt)
			mini = min(mini, cn)
		mini = min(mini, 3 - cnt['{}{}'.format(j, i)])
print(mini)


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)


DEBUG = False

def debug(to_print_args):
	if not DEBUG:
		return
	for arg in to_print_args:
		print(arg, end='')
	print()
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]:
	numbers.sort()
	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)


(a, b, c) = map(str, input().split())
s = [0] * 10
m = [0] * 10
p = [0] * 10
if list(a)[1] == 's':
	s[int(list(a)[0])] += 1
elif list(a)[1] == 'm':
	m[int(list(a)[0])] += 1
elif list(a)[1] == 'p':
	p[int(list(a)[0])] += 1
if list(b)[1] == 's':
	s[int(list(b)[0])] += 1
elif list(b)[1] == 'm':
	m[int(list(b)[0])] += 1
elif list(b)[1] == 'p':
	p[int(list(b)[0])] += 1
if list(c)[1] == 's':
	s[int(list(c)[0])] += 1
elif list(c)[1] == 'm':
	m[int(list(c)[0])] += 1
elif list(c)[1] == 'p':
	p[int(list(c)[0])] += 1
m1 = 0
for i in range(10):
	if m[i] > m1:
		m1 = m[i]
	if p[i] > m1:
		m1 = p[i]
	if s[i] > m1:
		m1 = s[i]
m2 = 0
for i in range(10):
	if s[i] > 1:
		s[i] = 1
	if p[i] > 1:
		p[i] = 1
	if m[i] > 1:
		m[i] = 1
for i in range(8):
	if sum(m[i:i + 3]) > m2:
		m2 = sum(m[i:i + 3])
	if sum(p[i:i + 3]) > m2:
		m2 = sum(p[i:i + 3])
	if sum(s[i:i + 3]) > m2:
		m2 = sum(s[i:i + 3])
print(3 - max(m1, m2))


s = list(map(str, input().split()))
for i in range(0, len(s)):
	s[i] = s[i][::-1]
s = sorted(s)
for i in range(0, len(s)):
	s[i] = s[i][::-1]
for i in range(0, len(s) - 2):
	if s[i] == s[i + 1] == s[i + 2]:
		print(0)
		exit(0)
	elif ord(s[i][0]) + 2 == ord(s[i + 1][0]) + 1 == ord(s[i + 2][0]) and s[i][1] == s[i + 1][1] == s[i + 2][1]:
		print(0)
		exit(0)
for i in range(0, len(s) - 1):
	if s[i] == s[i + 1]:
		print(1)
		exit(0)
	elif (ord(s[i][0]) + 1 == ord(s[i + 1][0]) or ord(s[i][0]) + 2 == ord(s[i + 1][0])) and s[i][1] == s[i + 1][1]:
		print(1)
		exit(0)
print(2)


a = [[0 for i in range(10)] for j in range(3)]
s = input().split()
m1 = 0
for i in s:
	k = int(i[0])
	if i[1] == 'm':
		a[0][k] += 1
		m1 = max(m1, a[0][k])
	elif i[1] == 'p':
		a[1][k] += 1
		m1 = max(m1, a[1][k])
	elif i[1] == 's':
		a[2][k] += 1
		m1 = max(m1, a[2][k])
m2 = 0
for i in range(3):
	for j in range(1, 8):
		if a[i][j] > 0:
			a[i][j] = 1
		if a[i][j + 1] > 0:
			a[i][j + 1] = 1
		if a[i][j + 2] > 0:
			a[i][j + 2] = 1
		m2 = max(a[i][j] + a[i][j + 1] + a[i][j + 2], m2)
print(min(3 - m1, 3 - m2))


import sys
(a, b, c) = sys.stdin.readline().strip().split()
if a == b and b == c:
	print(0)
elif a == b or b == c or a == c:
	print(1)
else:
	na = int(a[0])
	nb = int(b[0])
	nc = int(c[0])
	if a[1] == b[1] and a[1] == c[1]:
		cp = [na, nb, nc]
		cp.sort()
		cp[0] += 2
		cp[1] += 1
		if cp[0] == cp[1] and cp[1] == cp[2]:
			print('0')
		elif cp[0] == cp[1] or cp[1] == cp[2] or cp[0] == cp[1] or (cp[0] + 1 == cp[1]) or (cp[1] + 1 == cp[2]):
			print('1')
		else:
			print('2')
	elif a[1] == b[1]:
		mi = min(na, nb)
		ma = max(na, nb)
		if mi == ma - 1 or mi == ma - 2:
			print('1')
		else:
			print('2')
	elif a[1] == c[1]:
		mi = min(na, nc)
		ma = max(na, nc)
		if mi == ma - 1 or mi == ma - 2:
			print('1')
		else:
			print('2')
	elif b[1] == c[1]:
		mi = min(nb, nc)
		ma = max(nb, nc)
		if mi == ma - 1 or mi == ma - 2:
			print('1')
		else:
			print('2')
	else:
		print('2')


from sys import stdin, stdout
s = input()
s = s.split(' ')
M = [0] * 9
P = [0] * 9
S = [0] * 9
for pile in s:
	pile = list(pile)
	num = int(pile[0])
	tile = pile[1]
	if tile == 's':
		S[num - 1] += 1
	elif tile == 'p':
		P[num - 1] += 1
	elif tile == 'm':
		M[num - 1] += 1
for i in range(9):
	if M[i] == 3:
		print(0)
		quit()
	if P[i] == 3:
		print(0)
		quit()
	if S[i] == 3:
		print(0)
		quit()
for i in range(7):
	if M[i] == 1 and M[i + 1] == 1 and (M[i + 2] == 1):
		print(0)
		quit()
	if P[i] == 1 and P[i + 1] == 1 and (P[i + 2] == 1):
		print(0)
		quit()
	if S[i] == 1 and S[i + 1] == 1 and (S[i + 2] == 1):
		print(0)
		quit()
for i in range(9):
	if M[i] == 2:
		print(1)
		quit()
	if P[i] == 2:
		print(1)
		quit()
	if S[i] == 2:
		print(1)
		quit()
for i in range(8):
	if M[i] == 1 and M[i + 1] == 1:
		print(1)
		quit()
	if P[i] == 1 and P[i + 1] == 1:
		print(1)
		quit()
	if S[i] == 1 and S[i + 1] == 1:
		print(1)
		quit()
for i in range(7):
	if M[i] == 1 and M[i + 2] == 1:
		print(1)
		quit()
	if P[i] == 1 and P[i + 2] == 1:
		print(1)
		quit()
	if S[i] == 1 and S[i + 2] == 1:
		print(1)
		quit()
print(2)


inp = list(map(str, input().split()))
inp.sort()
slist = []
mlist = []
plist = []
ret = []
for i in inp:
	if i[1] == 's':
		slist.append(i)
	elif i[1] == 'm':
		mlist.append(i)
	elif i[1] == 'p':
		plist.append(i)
if len(slist) > 0:
	likes = 0
	sequence = 0
	middle = 0
	for s in range(len(slist) - 1):
		if int(slist[s][0]) == int(slist[s + 1][0]):
			likes += 1
		elif int(slist[s][0]) + 1 == int(slist[s + 1][0]):
			sequence += 1
		elif int(slist[s][0]) + 2 == int(slist[s + 1][0]):
			middle += 1
			break
	ret.append(2 - likes)
	ret.append(2 - sequence)
	ret.append(2 - middle)
if len(plist) > 0:
	likes = 0
	sequence = 0
	middle = 0
	for p in range(len(plist) - 1):
		if int(plist[p][0]) == int(plist[p + 1][0]):
			likes += 1
		elif int(plist[p][0]) + 1 == int(plist[p + 1][0]):
			sequence += 1
		elif int(plist[p][0]) + 2 == int(plist[p + 1][0]):
			middle += 1
			break
	ret.append(2 - likes)
	ret.append(2 - sequence)
	ret.append(2 - middle)
if len(mlist) > 0:
	likes = 0
	sequence = 0
	middle = 0
	for m in range(len(mlist) - 1):
		if int(mlist[m][0]) == int(mlist[m + 1][0]):
			likes += 1
		elif int(mlist[m][0]) + 1 == int(mlist[m + 1][0]):
			sequence += 1
		elif int(mlist[m][0]) + 2 == int(mlist[m + 1][0]):
			middle += 1
			break
	ret.append(2 - likes)
	ret.append(2 - sequence)
	ret.append(2 - middle)
print(min(ret))


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)))


l = input().split()
if len(set(l)) == 1:
	print(0)
else:
	d = dict()
	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(abs(i[j + 1] - i[j]))
				x = min(c)
				if x == 1 and c.count(1) == 2:
					mi = 0
				elif x == 1:
					if mi > 1:
						mi = 1
				elif x == 2:
					if mi > 1:
						mi = 1
				elif x == 0:
					y = c.count(0)
					y = 2 - y
					if y < mi:
						mi = y
				elif mi > 3:
					mi = 2
			elif len(i) == 2:
				x = abs(i[1] - i[0])
				if x == 0:
					if mi > 1:
						mi = 1
				elif x == 1 or x == 2:
					if mi > 1:
						mi = 1
				elif mi > 3:
					mi = 2
			else:
				x = 2
				if mi > x:
					mi = x
		elif mi > 3:
			mi = 3
	print(mi)


from __future__ import division, print_function
from sys import stdin, stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
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 = 1000000007
(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 % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)
	print(l)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d.keys():
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = {}
	for i in range(n):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s
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)


from __future__ import print_function
import sys

def get_seq(line):
	a = 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:
			return 1
		else:
			return 2
	elif len(a) == 3:
		if a[0] == a[1] and a[1] == a[2]:
			return 0
		elif a[1] - a[0] == 1 and a[2] - a[1] == 1:
			return 0
		elif a[1] - a[0] <= 2 or a[2] - a[1] <= 2:
			return 1
		else:
			return 2
seq = get_seq(input())
print(seq, file=sys.stderr)
print(get_best(seq))


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
a = list(map(str, input().split()))
m = {}
for i in range(3):
	if a[i] in m:
		m[a[i]] += 1
	else:
		m[a[i]] = 1
q = []
for i in range(3):
	q.append([].copy())
for i in range(3):
	if a[i][1] == 'p':
		q[0].append(a[i][0])
	elif a[i][1] == 'm':
		q[1].append(a[i][0])
	else:
		q[2].append(a[i][0])
best = -1
nst = 0
for i in range(3):
	q[i] = sorted(q[i])
	st = 1
	for j in range(len(q[i]) - 1):
		if int(q[i][j + 1]) - int(q[i][j]) == 1:
			st += 1
			if st > best:
				best = st
		else:
			if st > best:
				best = st
			st = 1
		if int(q[i][j + 1]) - int(q[i][j]) == 2:
			nst = 2
if best == 3:
	print(0)
	exit(0)
flag = 0
for i in m:
	if m[i] == 2:
		flag = 1
	if m[i] == 3:
		print(0)
		exit(0)
if best == 2 or nst == 2:
	print(1)
elif flag == 1:
	print(1)
else:
	print(2)


a = sorted(input().split())
ans = 2
for i in range(3):
	for j in range(i + 1, 3):
		if a[i] == a[j]:
			ans = 1
		elif a[i][1] == a[j][1] and abs(int(a[i][0]) - int(a[j][0])) < 3:
			ans = 1
if a[0] == a[2]:
	ans = 0
if a[0][1] == a[1][1] and a[1][1] == a[2][1] and (int(a[0][0]) == int(a[1][0]) - 1) and (int(a[1][0]) == int(a[2][0]) - 1):
	ans = 0
print(ans)


def mode(List):
	counter = 0
	num = List[0]
	for i in List:
		curr_frequency = List.count(i)
		if curr_frequency > counter:
			counter = curr_frequency
			num = i
	return num
(a, b, c) = map(str, input().split())
a = list(a)
b = list(b)
c = list(c)
numbers = [int(a[0]), int(b[0]), int(c[0])]
letters = [a[1], b[1], c[1]]
m = letters.count(mode(letters))
commonLetter = mode(letters)
n = numbers.count(mode(numbers))
if m == 2:
	l = []
	for i in range(3):
		if letters[i] == commonLetter:
			l.append(numbers[i])
	l.sort()
	if l[1] - l[0] < 3:
		print(1)
	else:
		print(2)
elif m == 3:
	if n == 3:
		print(0)
	elif n == 2:
		print(1)
	else:
		numbers.sort()
		ans = 2
		if numbers[0] + 1 == numbers[1]:
			ans -= 1
		if numbers[1] + 1 == numbers[2]:
			ans -= 1
		if numbers[1] - numbers[0] == 2:
			ans = 1
		if numbers[2] - numbers[1] == 2:
			ans = 1
		print(ans)
else:
	print(2)


input_data = str(input()).split(' ')
local_dict = {'m': 0, 's': 1, 'p': 2}

def koutsu_distance(data):
	top_same = 1
	for (i, tile) in enumerate(data[0:2]):
		local_same = 1
		for next_tile in data[i + 1:]:
			if next_tile == tile:
				local_same += 1
		if local_same > top_same:
			top_same = local_same
	return 3 - top_same

def shuntsu_distance(data):
	num_data = list(map(lambda x: int(x[0]) + 20 * local_dict[x[1]], data))
	max_diff = 0
	min_diff = 99
	for (i, num) in enumerate(num_data[:2]):
		for next_num in num_data[i + 1:]:
			diff = abs(num - next_num)
			if diff > max_diff:
				max_diff = diff
			if diff < min_diff:
				min_diff = diff
	if min_diff == 1 and max_diff == 2:
		return 0
	if min_diff <= 2:
		return 1
	return 2
koutsu = koutsu_distance(input_data)
shuntsu = shuntsu_distance(input_data)
print(min(koutsu, shuntsu))


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)


def iskoutsu(arr):
	return len(set(arr)) == 1

def isshuntsu(arr):
	nos = [int(ele[0]) for ele in arr]
	nos.sort()
	return nos[0] + 1 == nos[1] and nos[1] + 1 == nos[2] and (len(set([ele[1] for ele in arr])) == 1)
arr = input().strip().split()
if isshuntsu(arr) or iskoutsu(arr):
	exit(print(0))
total1 = 0
if len(set(arr)) == 3:
	total1 = 2
elif len(set(arr)) == 2:
	total1 = 1
total2 = 2
for ele in arr:
	(no, suite) = (int(ele[0]), ele[1])
	if no + 2 <= 9:
		required = [str(no + 1) + suite, str(no + 2) + suite]
		curr = int(required[0] not in arr) + (required[1] not in arr)
		total2 = min(total2, curr)
	if no + 1 <= 9 and no - 1 >= 0:
		required = [str(no - 1) + suite, str(no + 1) + suite]
		curr = int(required[0] not in arr) + (required[1] not in arr)
		total2 = min(total2, curr)
	if no + 2 <= 9:
		required = [str(no - 1) + suite, str(no - 2) + suite]
		curr = int(required[0] not in arr) + (required[1] not in arr)
		total2 = min(total2, curr)
print(min(total1, total2))


data = input().split()
data.sort()
dic = {'s': [], 'm': [], 'p': []}
for d in data:
	dic[d[1]].append(d)
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)
	elif lis[1] == lis[2]:
		print(1)
	else:
		ns = [int(a[0]) for a in lis]
		ns.sort()
		if ns[0] + 1 == ns[1]:
			if ns[1] + 1 == ns[2]:
				print(0)
			else:
				print(1)
		elif ns[0] + 2 == ns[1]:
			print(1)
		elif ns[1] + 1 == ns[2] or ns[1] + 2 == ns[2]:
			print(1)
		else:
			print(2)
elif len(lis) == 2:
	ns = [int(a[0]) for a in lis]
	ns.sort()
	if ns[0] == ns[1] or ns[0] + 1 == ns[1] or ns[0] + 2 == ns[1]:
		print(1)
	else:
		print(2)
else:
	print(2)


a = [x for x in input().split()]
flag = 0
m = [0 for x in range(10)]
p = [0 for x in range(10)]
s = [0 for x in range(10)]
m1 = 0
for i in a:
	if i[1] == 's':
		s[int(i[0])] = 1
	elif i[1] == 'p':
		p[int(i[0])] = 1
	elif i[1] == 'm':
		m[int(i[0])] = 1
	if a.count(i) == 3:
		flag = 1
		break
	elif a.count(i) == 2:
		m1 = 1
if flag == 0:
	t1 = ''.join((str(x) for x in p))
	t2 = ''.join((str(x) for x in m))
	t3 = ''.join((str(x) for x in s))
	if '111' in t1:
		flag = 1
	elif '111' in t2:
		flag = 1
	elif '111' in t3:
		flag = 1
	elif '11' in t1:
		m1 = 1
	elif '11' in t2:
		m1 = 1
	elif '11' in t3:
		m1 = 1
	elif '101' in t1:
		m1 = 1
	elif '101' in t2:
		m1 = 1
	elif '101' in t3:
		m1 = 1
if flag == 1:
	print('0')
elif m1 == 1:
	print('1')
else:
	print('2')


a = input().split()
for i in range(3):
	a[i] = [int(a[i][0]), a[i][1]]
a.sort()
if a[0][0] + 2 == a[1][0] + 1 == a[2][0] and a[0][1] == a[1][1] == a[2][1] or a[0] == a[1] == a[2]:
	print(0)
elif (a[0][0] + 1 == a[1][0] or a[0][0] + 2 == a[1][0]) and a[0][1] == a[1][1] or ((a[1][0] + 1 == a[2][0] or a[1][0] + 2 == a[2][0]) and a[1][1] == a[2][1]) or a[0] == a[1] or (a[1] == a[2]) or ((a[0][0] + 2 == a[2][0] or a[0][0] + 1 == a[2][0]) and a[0][1] == a[2][1]) or (a[0] == a[2]):
	print(1)
else:
	print(2)


(a, b, c) = input().split()
if a[1] == b[1] == c[1]:
	t = sorted([int(a[0]), int(b[0]), int(c[0])])
	if t[1] == t[0] + 1 == t[2] - 1 or t[0] == t[2]:
		print(0)
	elif t[0] == t[1] or t[1] == t[2]:
		print(1)
	elif t[0] + 1 == t[1] or t[1] + 1 == t[2] or t[0] + 2 == t[1] or (t[1] + 2 == t[2]):
		print(1)
	else:
		print(2)
elif a[1] == b[1]:
	(s, t) = (int(a[0]), int(b[0]))
	if s == t:
		print(1)
	elif min(s, t) + 1 == max(s, t) or min(s, t) + 2 == max(s, t):
		print(1)
	else:
		print(2)
elif c[1] == b[1]:
	(s, t) = (int(c[0]), int(b[0]))
	if s == t:
		print(1)
	elif min(s, t) + 1 == max(s, t) or min(s, t) + 2 == max(s, t):
		print(1)
	else:
		print(2)
elif a[1] == c[1]:
	(s, t) = (int(a[0]), int(c[0]))
	if s == t:
		print(1)
	elif min(s, t) + 1 == max(s, t) or min(s, t) + 2 == max(s, t):
		print(1)
	else:
		print(2)
else:
	print(2)


(a, b, c) = input().split()
ans = 2
if a == b == c:
	ans = 0
elif a[1] == b[1] == c[1]:
	l = sorted([int(a[0]), int(b[0]), int(c[0])])
	if l[0] == l[1] - 1 == l[2] - 2:
		ans = 0
if ans != 0:
	if a == b or b == c or a == c:
		ans = 1
	elif a[1] == b[1] and abs(int(a[0]) - int(b[0])) <= 2:
		ans = 1
	elif c[1] == b[1] and abs(int(c[0]) - int(b[0])) <= 2:
		ans = 1
	elif c[1] == a[1] and abs(int(c[0]) - int(a[0])) <= 2:
		ans = 1
print(ans)


l = [x for x in input().split()]
l.sort()
if l[0] == l[2]:
	print(0)
elif int(l[0][0]) + 2 == int(l[1][0]) + 1 == int(l[2][0]) and l[0][1] == l[1][1] == l[2][1]:
	print(0)
elif l[0][1] == l[1][1] and int(l[1][0]) - int(l[0][0]) <= 2:
	print(1)
elif l[1][1] == l[2][1] and int(l[2][0]) - int(l[1][0]) <= 2:
	print(1)
elif l[2][1] == l[0][1] and int(l[2][0]) - int(l[0][0]) <= 2:
	print(1)
else:
	print(2)


(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:
		p = letters.count('p')
		m = letters.count('m')
		s = letters.count('s')
		if a == b or b == c or a == c:
			print(1)
		elif p == 1 and m == 1 and (s == 1):
			print(2)
		elif 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:
			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)


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 len(arr)
	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[1] + 1 and arr[1] == arr[0] + 1:
		return 3
	elif arr[2] == arr[1] + 1 or arr[1] == arr[0] + 1 or arr[2] == arr[1] + 2 or (arr[1] == arr[0] + 2):
		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()


d = {}
for i in ['s', 'm', 'p']:
	for j in range(1, 10):
		d[str(j) + i] = 0
keys = list(d.keys())
for i in input().split():
	d[i] += 1

def is_valid0():
	for i in range(3):
		for j in range(9):
			if d[keys[i * 9:i * 9 + 9][j]] > 2:
				return True
		for j in range(7):
			if d[keys[i * 9:i * 9 + 9][j]] > 0 and d[keys[i * 9:i * 9 + 9][j + 1]] > 0 and (d[keys[i * 9:i * 9 + 9][j + 2]] > 0):
				return True
	return False

def is_valid1():
	for i in range(3):
		for j in range(9):
			if d[keys[i * 9:i * 9 + 9][j]] > 1:
				return True
		for j in range(7):
			if d[keys[i * 9:i * 9 + 9][j]] > 0 and d[keys[i * 9:i * 9 + 9][j + 1]] > 0:
				return True
			if d[keys[i * 9:i * 9 + 9][j + 1]] > 0 and d[keys[i * 9:i * 9 + 9][j + 2]] > 0:
				return True
			if d[keys[i * 9:i * 9 + 9][j]] > 0 and d[keys[i * 9:i * 9 + 9][j + 2]] > 0:
				return True
	return False
if is_valid0():
	print(0)
elif is_valid1():
	print(1)
else:
	print(2)


res = 3
pai = input().split()
M = [0, 0, 0, 0, 0, 0, 0, 0, 0]
S = [0, 0, 0, 0, 0, 0, 0, 0, 0]
P = [0, 0, 0, 0, 0, 0, 0, 0, 0]
for s in pai:
	if s[1] == 'm':
		M[int(s[0]) - 1] += 1
	elif s[1] == 's':
		S[int(s[0]) - 1] += 1
	else:
		P[int(s[0]) - 1] += 1
for i in range(9):
	if i > 1:
		cnt = 0
		for j in range(3):
			cnt += M[i - j] != 0
		res = min(res, 3 - cnt)
	res = min(res, 3 - M[i])
for i in range(9):
	if i > 1:
		cnt = 0
		for j in range(3):
			cnt += P[i - j] != 0
		res = min(res, 3 - cnt)
	res = min(res, 3 - P[i])
for i in range(9):
	if i > 1:
		cnt = 0
		for j in range(3):
			cnt += S[i - j] != 0
		res = min(res, 3 - cnt)
	res = min(res, 3 - S[i])
print(res)


list_str = input().split()
list_str.sort()

def main():
	if len(set(list_str)) == 1:
		print(0)
		return 0
	elif len(set(list_str)) == 2:
		print(1)
		return 0
	shuntsu_count = 0
	num = []
	lstr = []
	for e in list_str:
		num.append(int(e[0]))
		lstr.append(e[1])
	if lstr[0] == lstr[1] and num[1] - num[0] <= 2 and (num[0] != num[1]):
		shuntsu_count += 1
	if lstr[0] == lstr[2] and num[2] - num[0] <= 2 and (num[0] != num[2]):
		shuntsu_count += 1
	if lstr[1] == lstr[2] and num[2] - num[1] <= 2 and (num[1] != num[2]):
		shuntsu_count += 1
	if shuntsu_count >= 3:
		print(0)
	elif shuntsu_count == 0:
		print(2)
	else:
		print(1)
main()


A = list(map(list, list(input().split())))
m = []
p = []
s = []
for (x, a) in A:
	if a == 'm':
		m.append(int(x))
	elif a == 'p':
		p.append(int(x))
	else:
		s.append(int(x))
m.sort()
p.sort()
s.sort()

def check(x):
	if len(x) == 3:
		if x[0] == x[1] == x[2]:
			return 3
		if x[0] + 1 == x[1] and x[1] + 1 == x[2]:
			return 3
		if x[0] == x[1] or x[1] == x[2]:
			return 2
		if x[0] + 1 == x[1] or x[1] + 1 == x[2] or x[0] + 2 == x[1] or (x[1] + 2 == x[2]):
			return 2
		return 1
	if len(x) == 2:
		if x[0] == x[1]:
			return 2
		if x[0] + 1 == x[1] or x[0] + 2 == x[1]:
			return 2
		return 1
	return 1
print(3 - max(check(m), check(p), check(s)))


s = list(map(str, input().split()))
ans = 10 ** 18
for i in map(str, range(1, 10)):
	for p in ('m', 'p', 's'):
		k = s.count(i + p)
		if 3 - k < ans:
			ans = 3 - k
for i in range(1, 8):
	for p in ('m', 'p', 's'):
		k = 0
		if str(i) + p in s:
			k += 1
		if str(i + 1) + p in s:
			k += 1
		if str(i + 2) + p in s:
			k += 1
		if 3 - k < ans:
			ans = 3 - k
print(ans)


(a, b, c) = map(str, input().split())
if a == b == c:
	print(0)
	exit(0)
p = [int(a[0]), int(b[0]), int(c[0])]
p.sort()
if a[1] == b[1] == c[1] and p[2] - p[1] == p[1] - p[0] == 1:
	print(0)
elif a == b:
	print(1)
elif b == c:
	print(1)
elif a == c:
	print(1)
elif a[1] != b[1] and b[1] != c[1] and (c[1] != a[1]):
	print(2)
elif a[1] == b[1] and b[1] != c[1] and (abs(int(a[0]) - int(b[0])) == 1 or abs(int(a[0]) - int(b[0])) == 2):
	print(1)
elif c[1] == b[1] and b[1] != a[1] and (abs(int(c[0]) - int(b[0])) == 1 or abs(int(c[0]) - int(b[0])) == 2):
	print(1)
elif a[1] == c[1] and b[1] != c[1] and (abs(int(a[0]) - int(c[0])) == 1 or abs(int(a[0]) - int(c[0])) == 2):
	print(1)
elif a[1] == b[1] and b[1] == c[1] and (abs(int(a[0]) - int(b[0])) > 2) and (abs(int(c[0]) - int(b[0])) > 2) and (abs(int(a[0]) - int(c[0])) > 2):
	print(2)
elif a[1] == b[1] and (abs(int(a[0]) - int(b[0])) == 1 or abs(int(a[0]) - int(b[0])) == 2):
	print(1)
elif c[1] == b[1] and (abs(int(c[0]) - int(b[0])) == 1 or abs(int(c[0]) - int(b[0])) == 2):
	print(1)
elif a[1] == c[1] and (abs(int(a[0]) - int(c[0])) == 1 or abs(int(a[0]) - int(c[0])) == 2):
	print(1)
elif a[1] == c[1] and abs(int(a[0]) - int(c[0])) == 3:
	print(2)
elif a[1] == b[1] and abs(int(a[0]) - int(b[0])) == 3:
	print(2)
elif b[1] == c[1] and abs(int(b[0]) - int(c[0])) == 3:
	print(2)
elif a[1] == b[1] == c[1] and (abs(int(a[0]) - int(b[0])) == 2 or abs(int(c[0]) - int(b[0])) or abs(int(a[0]) - int(c[0]))):
	print(1)
else:
	print(2)


Input = lambda : map(str, input().split())
s = list(Input())
s.sort()
num = list()
for i in range(3):
	num.append(int(s[i][0]))
if s[0] == s[1] == s[2]:
	print(0)
	exit()
if s[0][1] == s[1][1] == s[2][1] and num[0] + 2 == num[1] + 1 == num[2]:
	print(0)
	exit()
if s[0] == s[1] or s[1] == s[2]:
	print(1)
	exit()
h = str(s.copy())
if h.count('s') in [2, 3]:
	ind = -1
	if s[0][1] != 's':
		ind = 0
	elif s[1][1] != 's':
		ind = 1
	elif s[2][1] != 's':
		ind = 2
	else:
		pass
	if ind == -1:
		x1 = num[0]
		x2 = num[1]
		x3 = num[2]
		if x2 - x1 <= 2:
			print(1)
			exit()
		if x3 - x2 <= 2:
			print(1)
			exit()
	else:
		if ind == 0:
			x1 = num[1]
			x2 = num[2]
		elif ind == 1:
			x1 = num[0]
			x2 = num[2]
		else:
			x1 = num[0]
			x2 = num[1]
		if x2 - x1 <= 2:
			print(1)
			exit()
elif h.count('m') in [2, 3]:
	ind = -1
	if s[0][1] != 'm':
		ind = 0
	elif s[1][1] != 'm':
		ind = 1
	elif s[2][1] != 'm':
		ind = 2
	else:
		pass
	if ind == -1:
		x1 = num[0]
		x2 = num[1]
		x3 = num[2]
		if x2 - x1 <= 2:
			print(1)
			exit()
		if x3 - x2 <= 2:
			print(1)
			exit()
	else:
		if ind == 0:
			x1 = num[1]
			x2 = num[2]
		elif ind == 1:
			x1 = num[0]
			x2 = num[2]
		else:
			x1 = num[0]
			x2 = num[1]
		if x2 - x1 <= 2:
			print(1)
			exit()
elif h.count('p') in [2, 3]:
	ind = -1
	if s[0][1] != 'p':
		ind = 0
	elif s[1][1] != 'p':
		ind = 1
	elif s[2][1] != 'p':
		ind = 2
	else:
		pass
	if ind == -1:
		x1 = num[0]
		x2 = num[1]
		x3 = num[2]
		if x2 - x1 <= 2:
			print(1)
			exit()
		if x3 - x2 <= 2:
			print(1)
			exit()
	else:
		if ind == 0:
			x1 = num[1]
			x2 = num[2]
		elif ind == 1:
			x1 = num[0]
			x2 = num[2]
		else:
			x1 = num[0]
			x2 = num[1]
		if x2 - x1 <= 2:
			print(1)
			exit()
else:
	pass
print(2)


(n1, n2, n3) = input().split()
(n1, n2, n3) = sorted([n1, n2, n3])
if ord(n1[1]) == ord(n2[1]) == ord(n3[1]):
	if n1 == n2 == n3 or int(n1[0]) + 2 == int(n2[0]) + 1 == int(n3[0]):
		print(0)
	elif n1[1] == n2[1] or n2[1] == n3[1] or n1[1] == n3[1]:
		if n1 == n2 or n2 == n3 or int(n1[0]) + 1 == int(n2[0]) or (int(n1[0]) + 2 == int(n2[0])) or (int(n2[0]) + 1 == int(n3[0])) or (int(n2[0]) + 2 == int(n3[0])) or (int(n1[0]) + 1 == int(n3[0])) or (int(n1[0]) + 2 == int(n3[0])):
			print(1)
		else:
			print(2)
	else:
		print(2)
elif n1[1] == n2[1] or n2[1] == n3[1] or n1[1] == n3[1]:
	if n2[1] == n3[1]:
		(n1, n2) = (n2, n3)
	if n1[1] == n3[1]:
		(n1, n2) = (n1, n3)
	if n1 == n2 or int(n1[0]) + 1 == int(n2[0]) or int(n1[0]) + 2 == int(n2[0]):
		print(1)
	else:
		print(2)
else:
	print(2)


import sys
import math
from collections import defaultdict
a = list(input().split())
d = {}
b = []
c = 0
for x in a:
	if x[1] in d:
		d[x[1]].append(int(x[0]))
	else:
		d[x[1]] = [int(x[0])]
		b.append(x[1])
		c += 1
if c == 1:
	t = b[0]
	d[b[0]].sort()
	if d[t][1] - d[t][0] == 1 and d[t][2] - d[t][1] == 1 or (d[t][1] - d[t][0] == 0 and d[t][2] - d[t][1] == 0):
		print('0')
	elif d[t][1] - d[t][0] == 1 or d[t][2] - d[t][1] == 1 or d[t][2] - d[t][1] == 0 or (d[t][0] - d[t][1] == 0) or (d[t][2] - d[t][0] == 0) or (abs(d[t][2] - d[t][1]) == 2) or (abs(d[t][2] - d[t][0]) == 2) or (abs(d[t][0] - d[t][1]) == 2):
		print('1')
	else:
		print('2')
elif c == 2:
	t1 = b[0]
	t2 = b[1]
	l1 = len(d[t1])
	l2 = len(d[t2])
	if l1 == 2 and (abs(d[t1][0] - d[t1][1]) == 1 or abs(d[t1][0] - d[t1][1]) == 0 or abs(d[t1][0] - d[t1][1]) == 2):
		print('1')
	elif l2 == 2 and (abs(d[t2][0] - d[t2][1]) == 1 or abs(d[t2][0] - d[t2][1]) == 0 or abs(d[t2][0] - d[t2][1]) == 2):
		print('1')
	else:
		print('2')
else:
	print('2')


a = input().split()
a.sort()
if a[0] == a[1] == a[2]:
	print(0)
	exit()
elif a[0] == a[1] or a[1] == a[2]:
	print(1)
	exit()
a1 = []
for i in range(3):
	a1.append([int(a[i][0]), a[i][1]])
a1.sort()
if a1[1][1] == a1[2][1] == a1[0][1]:
	if a1[0][0] == a1[1][0] - 1 and a1[0][0] == a1[2][0] - 2:
		print(0)
		exit()
	found = False
	for i in range(3):
		for j in range(3):
			if abs(a1[i][0] - a1[j][0]) == 1 or abs(a1[i][0] - a1[j][0]) == 2:
				print(1)
				exit()
	print(2)
	exit()
for i in range(3):
	for j in range(i + 1, 3):
		if a1[i][1] == a1[j][1]:
			if a1[i][0] == a1[j][0] - 1 or a1[i][0] == a1[j][0] - 2:
				print(1)
			else:
				print(2)
			exit()
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))


def majong(tiles):
	(result, flag) = (2, 0)
	if tiles[0] == tiles[1] and tiles[1] == tiles[2]:
		result = 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:
				result = 1
				if int(tiles[0][0]) == int(tiles[1][0]) - 1:
					flag = 1
		if tiles[1][1] == tiles[2][1]:
			if int(tiles[1][0]) == int(tiles[2][0]) - 1:
				result = 1
				if flag:
					result = 0
			if int(tiles[1][0]) == int(tiles[2][0]) - 2:
				result = 1
		if tiles[0][1] == tiles[2][1]:
			if int(tiles[0][0]) >= int(tiles[2][0]) - 2 and flag != 1:
				result = 1
	else:
		result = 1
	return result
s = input().split(' ')
print(majong(sorted(s)))


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)


def check(l, r, d=1):
	return l[0] == r[0] - d and l[1] == r[1]
s = [i for i in input().split()]
a = []
for i in s:
	a.append([int(i[0]), i[1]])
a.sort()
if s[0] == s[1] == s[2] or (check(a[0], a[1]) and check(a[1], a[2])):
	print(0)
elif (s[0] == s[1] or s[0] == s[2] or s[1] == s[2]) or (check(a[0], a[1], 2) or check(a[0], a[1]) or check(a[0], a[2], 2) or check(a[0], a[2]) or check(a[1], a[2], 2) or check(a[1], a[2])):
	print(1)
else:
	print(2)


d = [[0] * 10 for i in range(3)]
for i in input().split():
	if i[1] == 'm':
		d[0][int(i[0])] += 1
	elif i[1] == 'p':
		d[1][int(i[0])] += 1
	else:
		d[2][int(i[0])] += 1
for i in range(3):
	for j in range(10):
		if d[i][j] == 3:
			print(0)
			exit()
for i in range(3):
	for j in range(10):
		if d[i][j] == 2:
			print(1)
			exit()
for i in d:
	for j in range(1, 8):
		if sum(i[j:j + 3]) == 3:
			print(0)
			exit()
for i in d:
	for j in range(1, 8):
		if sum(i[j:j + 3]) == 2:
			print(1)
			exit()
print(2)


def main():
	nums = []
	chars = []
	for elm in input().split(' '):
		(num, char) = list(elm)
		num = int(num)
		nums.append(num)
		chars.append(char)
	set_char = list(set(chars))
	for (i, char) in enumerate(set_char):
		tmp_count = chars.count(char)
		if i == 0:
			max_i = 0
			max_count = tmp_count
			max_char = char
		elif tmp_count > max_count:
			max_count = tmp_count
			max_i = i
			max_char = char
	if max_count == 1:
		return 2
	sub_nums = sorted([nums[i] for i in range(3) if chars[i] == max_char])
	diff1 = sub_nums[1] - sub_nums[0]
	if max_count == 3:
		diff2 = sub_nums[2] - sub_nums[1]
		if diff1 == 0 and diff2 == 0 or (diff1 == 1 and diff2 == 1):
			return 0
		elif diff1 == 1 or diff2 == 1 or diff1 == 0 or (diff2 == 0) or (diff1 == 2) or (diff2 == 2):
			return 1
		else:
			return 2
	elif diff1 == 1 or diff1 == 0 or diff1 == 2:
		return 1
	else:
		return 2
out = main()
print(out)


class cinn:

	def __init__(self):
		self.x = []

	def cin(self, t=int):
		if len(self.x) == 0:
			a = input()
			self.x = a.split()
			self.x.reverse()
		return self.get(t)

	def get(self, t):
		return t(self.x.pop())

	def clist(self, n, t=int):
		l = [0] * n
		for i in range(n):
			l[i] = self.cin(t)
		return l

	def clist2(self, n, t1=int, t2=int, t3=int, tn=2):
		l = [0] * n
		for i in range(n):
			if tn == 2:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				l[i] = (a1, a2)
			elif tn == 3:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				a3 = self.cin(t3)
				l[i] = (a1, a2, a3)
		return l

	def clist3(self, n, t1=int, t2=int, t3=int):
		return self.clist2(self, n, t1, t2, t3, 3)

	def cout(self, i, ans=''):
		if ans == '':
			print('Case #' + str(i + 1) + ':', end=' ')
		else:
			print('Case #' + str(i + 1) + ':', ans)

	def printf(self, thing):
		print(thing, end='')

	def countlist(self, l, s=0, e=None):
		if e == None:
			e = len(l)
		dic = {}
		for el in range(s, e):
			if l[el] not in dic:
				dic[l[el]] = 1
			else:
				dic[l[el]] += 1
		return dic

	def talk(self, x):
		print(x, flush=True)

	def dp1(self, k):
		L = [-1] * k
		return L

	def dp2(self, k, kk):
		L = [-1] * k
		for i in range(k):
			L[i] = [-1] * kk
		return L

	def isprime(self, n):
		if n == 1 or n == 0:
			return False
		for i in range(2, int(n ** 0.5 + 1)):
			if n % i == 0:
				return False
		return True

	def factors(self, n):
		from functools import reduce
		return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

	def nthprime(self, n):
		i = 0
		s = 2
		L = []
		while i < n:
			while not self.isprime(s):
				s += 1
			L.append(s)
			s += 1
			i += 1
		return L

	def matrixin(self, m, n, t=int):
		L = []
		for i in range(m):
			p = self.clist(n, t)
			L.append(p)
		return L

	def seive(self, k):
		n = k + 1
		L = [True] * n
		L[1] = False
		L[0] = False
		for i in range(2, n):
			if L[i] == True:
				for j in range(2 * i, n, i):
					L[j] = False
		return L

	def seiven(self, n, L):
		i = 0
		for j in range(len(L)):
			if L[j] == True:
				i += 1
			if i == n:
				return j

	def matrixin2(self, m, t=int):
		L = []
		for i in range(m):
			iny = self.cin(str)
			lsmall = []
			for el in iny:
				lsmall.append(t(el))
			L.append(lsmall)
		return L
c = cinn()
ca1 = c.cin(str)
ca2 = c.cin(str)
ca3 = c.cin(str)
L = [ca1, ca2, ca3]
if ca1 == ca2 and ca2 == ca3:
	print(0)
elif ca1 == ca2 or ca3 == ca2 or ca1 == ca3:
	print(1)
else:
	a1 = list(ca1)
	a2 = list(ca2)
	a3 = list(ca3)
	l = [int(a1[0]), int(a2[0]), int(a3[0])]
	l.sort()
	found1 = False
	if l[0] == l[1] - 1 and l[1] == l[2] - 1:
		if a1[1] == a2[1] and a1[1] == a3[1]:
			print(0)
			found1 = True
	if found1 == False:
		found = False
		for el in L:
			upel = str(int(el[0]) + 1) + el[1]
			downel = str(int(el[0]) - 1) + el[1]
			downel2 = str(int(el[0]) - 2) + el[1]
			upel2 = str(int(el[0]) + 2) + el[1]
			if downel in L or upel in L or upel2 in L or (downel2 in L):
				found = True
		if found:
			print(1)
		else:
			print(2)


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


s = [[], [], []]
st = list(input().split())
for i in st:
	if i[1] == 'm':
		s[0].append(int(i[0]))
	if i[1] == 'p':
		s[1].append(int(i[0]))
	if i[1] == 's':
		s[2].append(int(i[0]))
ans = 2
for i in s:
	if len(i) == 1:
		ans = min(ans, 2)
	elif len(i) == 2:
		i.sort()
		if i[1] == i[0] + 1 or i[1] == i[0] + 2:
			ans = min(ans, 1)
		elif i[1] == i[0]:
			ans = min(ans, 1)
		else:
			ans = min(ans, 2)
	elif len(i) == 3:
		i.sort()
		if i[2] == i[1] and i[1] == i[0]:
			ans = 0
		if i[2] == i[1] + 1 and i[1] == i[0] + 1:
			ans = 0
		elif i[2] == i[1] and i[1] == i[0]:
			ans = 0
		elif i[1] == i[0] + 1 or i[1] == i[0] + 2:
			ans = min(ans, 1)
		elif i[2] == i[1] + 1 or i[2] == i[1] + 2:
			ans = min(ans, 1)
		elif i[2] == i[0] + 1 and i[2] == i[0] + 2:
			ans = min(ans, 1)
		elif i[0] == i[1] or i[1] == i[2]:
			ans = min(ans, 1)
		else:
			ans = min(ans, 2)
print(ans)


l = input().split()
p = [0] * 10
s = [0] * 10
m = [0] * 10
for i in l:
	if i[1] == 'p':
		p[int(i[0])] += 1
	if i[1] == 's':
		s[int(i[0])] += 1
	if i[1] == 'm':
		m[int(i[0])] += 1
ans1 = max(max(s), max(m), max(p))
ans2 = 0
for x in (p, s, m):
	for i in range(1, 8):
		t = sum([1 for j in x[i:i + 3] if j])
		if t > ans2:
			ans2 = t
print(3 - max(ans1, ans2))


from math import *
import sys
input = lambda : sys.stdin.readline().strip()
d = {'m': [], 's': [], 'p': []}
ls = list(input().split())
for i in ls:
	d[i[1]].append(int(i[0]))
for (k, v) in d.items():
	v.sort()
	if len(v) == 3 and len(set(v)) == 1:
		print(0)
		break
	if len(v) == 3 and v[0] + 1 == v[1] and (v[1] + 1 == v[2]):
		print(0)
		break
else:
	for (k, v) in d.items():
		if len(v) == 2 and len(set(v)) == 1:
			print(1)
			break
		if len(v) == 2 and v[1] - v[0] <= 2:
			print(1)
			break
		if len(v) == 3 and (v[0] == v[1] or v[1] == v[2]):
			print(1)
			break
		if len(v) == 3 and (v[1] - v[0] <= 2 or v[2] - v[1] <= 2):
			print(1)
			break
	else:
		print(2)


a = [0] * 26
d = {'p': [], 's': [], 'm': []}
for i in input().split():
	d[i[1]] += (int(i[0]),)
	a[ord(i[1]) - 97] += 1
if max(a) == 1:
	print(2)
else:
	x = chr(a.index(max(a)) + 97)
	v = []
	if len(d[x]) == 2:
		g = abs(d[x][0] - d[x][1])
		if g == 1 or g == 0 or g == 2:
			print(1)
		else:
			print(2)
	else:
		v += (abs(d[x][0] - d[x][1]),)
		v += (abs(d[x][0] - d[x][2]),)
		v += (abs(d[x][1] - d[x][2]),)
		if v.count(0) > 1:
			print(0)
		elif v.count(0) == 1:
			print(1)
		elif v.count(1) == 2:
			print(0)
		elif v.count(1) == 1 or v.count(2):
			print(1)
		else:
			print(2)


x = []
x = input().split(' ')
(x1, x2, x3) = [x[i] for i in range(len(x))]
newx = sorted(x)
if x1 == x2 and x2 == x3:
	print('0')
elif x1 == x2 or x1 == x3 or x2 == x3:
	print('1')
else:
	(x1, x2, x3) = [newx[i] for i in range(len(newx))]
	if x1[1] == x2[1] and x2[1] == x3[1] and (abs(int(x1[0]) - int(x2[0])) == 1) and (abs(int(x2[0]) - int(x3[0])) == 1):
		print('0')
	elif x1[1] == x2[1] and (abs(int(x1[0]) - int(x2[0])) == 1 or abs(int(x1[0]) - int(x2[0])) == 2):
		print('1')
	elif x2[1] == x3[1] and (abs(int(x2[0]) - int(x3[0])) == 1 or abs(int(x2[0]) - int(x3[0])) == 2):
		print('1')
	elif x3[1] == x1[1] and (abs(int(x3[0]) - int(x1[0])) == 1 or abs(int(x3[0]) - int(x1[0])) == 2):
		print('1')
	else:
		print('2')


a = input().split()
r = 2
for i in range(48, 58):
	for c in 'mps':
		r = min(r, max(0, 3 - a.count(chr(i) + c)))
		r = min(r, (not chr(i - 1) + c in a) + (not chr(i) + c in a) + (not chr(i + 1) + c in a))
print(r)


tiles = {'m': [], 'p': [], 's': []}
for tile in input().split():
	tiles[tile[1]].append(int(tile[0]))
max_ava = 0
for suit in tiles:
	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)
	for x in range(1, 10):
		count = tiles[suit].count(x)
		max_ava = max(max_ava, count)
print(3 - max_ava)


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)


import sys
inp = input().split()
m = [0] * 10
s = [0] * 10
p = [0] * 10
for st in inp:
	if st[1] == 'm':
		m[int(st[0])] += 1
	if st[1] == 's':
		s[int(st[0])] += 1
	if st[1] == 'p':
		p[int(st[0])] += 1
res = 3
for i in range(1, 10):
	res = min(res, 3 - m[i])
	res = min(res, 3 - s[i])
	res = min(res, 3 - p[i])
for i in range(1, 8):
	cnt = sum(map(lambda x: 1 if x == 0 else 0, m[i:i + 3]))
	res = min(res, cnt)
	cnt = sum(map(lambda x: 1 if x == 0 else 0, s[i:i + 3]))
	res = min(res, cnt)
	cnt = sum(map(lambda x: 1 if x == 0 else 0, p[i:i + 3]))
	res = min(res, cnt)
print(res)


s = input().split()
s.sort()
if s[0] == s[1] == s[2]:
	print(0)
	exit()
if s[0][1] == s[1][1] == s[2][1]:
	if ord(s[0][0]) + 1 == ord(s[1][0]) == ord(s[2][0]) - 1:
		print(0)
		exit()
if s[0][1] == s[1][1] and ord(s[0][0]) + 2 >= ord(s[1][0]) or (s[1][1] == s[2][1] and ord(s[1][0]) + 2 >= ord(s[2][0])) or (s[0][1] == s[2][1] and ord(s[0][0]) + 2 >= ord(s[2][0])):
	print(1)
	exit()
if s[0] == s[1] or s[1] == s[2] or s[0] == s[2]:
	print(1)
	exit()
print(2)


l = input().split()
p = []
m = []
s = []
for i in l:
	if i[1] == 'p':
		p.append(int(i[0]))
	if i[1] == 'm':
		m.append(int(i[0]))
	if i[1] == 's':
		s.append(int(i[0]))
same = 1
conseq = 1
ans = 2
if p and m and s:
	print(2)
	exit()
if len(p) > 1:
	p.sort()
	for i in p:
		same = max(same, p.count(i))
	for i in range(len(p) - 1):
		j = i + 1
		if p[j] - p[i] == 1:
			conseq += 1
	for i in range(len(p) - 1):
		j = i + 1
		if p[j] - p[i] == 2:
			conseq = max(conseq, 2)
if len(m) > 1:
	m.sort()
	for i in m:
		same = max(same, m.count(i))
	for i in range(len(m) - 1):
		j = i + 1
		if m[j] - m[i] == 1:
			conseq += 1
	for i in range(len(m) - 1):
		j = i + 1
		if m[j] - m[i] == 2:
			conseq = max(conseq, 2)
if len(s) > 1:
	s.sort()
	for i in s:
		same = max(same, s.count(i))
	for i in range(len(s) - 1):
		j = i + 1
		if s[j] - s[i] == 1:
			conseq += 1
	for i in range(len(s) - 1):
		j = i + 1
		if s[j] - s[i] == 2:
			conseq = max(conseq, 2)
print(min(2, 3 - max(same, conseq)))


from collections import Counter
import sys
readline = sys.stdin.readline

def calc(t):
	ct = Counter(t)
	if not t:
		return 3
	shun = max((sum((ct[c + i] > 0 for i in range(-1, 2))) for c in range(2, 9)))
	ko = max((min(3, ct[i]) for i in range(1, 10)))
	res = max(ko, shun)
	if res == 3:
		return 0
	if res == 2:
		return 1
	if res == 1:
		return 2
	assert True, ''
Hand = list(readline().strip().split())
Manzu = [int(h[0]) for h in Hand if h[1] == 'm']
Pinzu = [int(h[0]) for h in Hand if h[1] == 'p']
Souzu = [int(h[0]) for h in Hand if h[1] == 's']
print(min((calc(t) for t in [Manzu, Pinzu, Souzu])))


(a, b, c) = input().split()
n = [a[0], b[0], c[0]]
s = [a[1], b[1], c[1]]
if len(set(s)) == 1 and (len(set(n)) == 1 or ''.join(sorted(n)) in '123456789'):
	print(0)
else:
	a = 0
	for i in range(3):
		if s[i] == s[(i + 1) % 3] and abs(int(n[i]) - int(n[(i + 1) % 3])) in [0, 1, 2]:
			print(1)
			a = 1
			break
	if a == 0:
		print(2)


s = input()
a = s[0:2]
b = s[3:5]
c = s[6] + s[7]
l = [int(a[0]), int(b[0]), int(c[0])]
l.sort()
if a == b and a == c:
	print(0)
elif l[1] == l[0] + 1 and l[2] == l[0] + 2 and (a[1] == b[1]) and (a[1] == c[1]):
	print(0)
elif a == b and a != c or (a == c and a != b) or (b == c and b != a):
	print(1)
elif l[1] == l[0] + 1 or l[2] == l[1] + 1:
	if abs(int(a[0]) - int(b[0])) == 1 and a[1] == b[1]:
		print(1)
	elif abs(int(b[0]) - int(c[0])) == 1 and b[1] == c[1]:
		print(1)
	elif abs(int(a[0]) - int(c[0])) == 1 and a[1] == c[1]:
		print(1)
	elif l[2] == l[0] + 2 or l[1] == l[0] + 2 or l[2] == l[1] + 2:
		if abs(int(a[0]) - int(b[0])) == 2 and a[1] == b[1]:
			print(1)
		elif abs(int(b[0]) - int(c[0])) == 2 and b[1] == c[1]:
			print(1)
		elif abs(int(a[0]) - int(c[0])) == 2 and a[1] == c[1]:
			print(1)
		else:
			print(2)
	else:
		print(2)
elif l[2] == l[0] + 2 or l[1] == l[0] + 2 or l[2] == l[1] + 2:
	if abs(int(a[0]) - int(b[0])) == 2 and a[1] == b[1]:
		print(1)
	elif abs(int(b[0]) - int(c[0])) == 2 and b[1] == c[1]:
		print(1)
	elif abs(int(a[0]) - int(c[0])) == 2 and a[1] == c[1]:
		print(1)
	else:
		print(2)
elif l[2] == l[1] + 1 and (a[1] == b[1] and a != c or (b[1] == c[1] and b != a) or (a[1] == c[1] and a != b)):
	print(1)
else:
	print(2)


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)
			if int(t[k + 1][0]) == int(t[k][0]) + 2:
				ans = min(ans, 1)
	l = r
print(ans)


(a, b, c) = [x for x in input().split(' ')]
n = 0
if a == b and b == c:
	n = 0
elif a == b or b == c or c == a:
	n = 1
elif a[1] == b[1] and a[1] == c[1]:
	z = [int(a[0]), int(b[0]), int(c[0])]
	z.sort()
	if a[0] == b[0] or b[0] == c[0] or a[0] == c[0]:
		n = 1
	elif z[2] - z[1] == 1 and z[1] - z[0] == 1:
		n = 0
	elif abs(int(a[0]) - int(b[0])) in [1, 2] or abs(int(a[0]) - int(c[0])) in [1, 2] or abs(int(b[0]) - int(c[0])) in [1, 2]:
		n = 1
	else:
		n = 2
elif a[1] == b[1] or a[1] == c[1] or b[1] == c[1]:
	if a[1] == b[1] and abs(int(a[0]) - int(b[0])) in [1, 2]:
		n = 1
	elif a[1] == c[1] and abs(int(a[0]) - int(c[0])) in [1, 2]:
		n = 1
	elif c[1] == b[1] and abs(int(c[0]) - int(b[0])) in [1, 2]:
		n = 1
	else:
		n = 2
else:
	n = 2
print(n)


t = list(map(str, input().split()))
t.sort(key=lambda x: x[1] + x[0])
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
		elif 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))


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)
	elif d2 == 0 or d2 == 1:
		print(1)
	else:
		print(2)


import collections as cl
v = sorted(input().split())
cnt = cl.Counter(v)
seq = 1
if int(v[0][0]) + 1 == int(v[1][0]) and v[0][1] == v[1][1]:
	if int(v[1][0]) + 1 == int(v[2][0]) and v[1][1] == v[2][1]:
		seq = 3
	else:
		seq = 2
elif int(v[0][0]) + 2 == int(v[1][0]) and v[0][1] == v[1][1]:
	seq = 2
elif int(v[0][0]) + 1 == int(v[2][0]) and v[0][1] == v[2][1]:
	seq = 2
elif int(v[1][0]) + 1 == int(v[2][0]) and v[1][1] == v[2][1]:
	seq = 2
elif int(v[0][0]) + 2 == int(v[2][0]) and v[0][1] == v[2][1]:
	seq = 2
elif int(v[1][0]) + 2 == int(v[2][0]) and v[1][1] == v[2][1]:
	seq = 2
print(3 - max(seq, max(cnt.values())))


arr = input().split(' ')
arr = set(arr)
ans = 2
tmp = [0] * 3
for i in arr:
	for j in arr:
		if i[1] == j[1] and 1 <= int(i[0]) - int(j[0]) <= 2:
			if int(i[0]) - int(j[0]) == 1:
				tmp[1] += 1
			else:
				tmp[2] = 1
ans -= max(tmp)
ans = min(ans, len(arr) - 1)
print(max(0, ans))


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(1)
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)


from collections import Counter
a = list(input().split())
s = set(a)
r = 3
for b in a:
	(b1, b2) = (int(b[0]), b[1])
	for i in range(3):
		(c1, c2, c3) = (b1 - 2 + i, b1 - 1 + i, b1 + i)
		if c1 > 0 and c3 < 10:
			d = set([str(c1) + b2, str(c2) + b2, str(c3) + b2])
			r = min(r, len(d - s))
			if r == 0:
				print(r)
				exit(0)
	r = min(r, 3 - Counter(a).get(b))
	if r == 0:
		print(r)
		exit(0)
print(r)


def issort(a, b, c):
	l = [a, b, c]
	l = sorted(l)
	if l[1] - l[0] == 1 and l[2] - l[1] == 1:
		return 0
	elif l[1] - l[0] == 1 or l[2] - l[1] == 1 or l[1] - l[0] == 2 or (l[2] - l[1] == 2):
		return 1
	return 2
(a, b, c) = input().split()
rk = 2
if a == b == c:
	rk = 0
elif a == b or b == c or c == a:
	rk = 1
a = str(a)
b = str(b)
c = str(c)
sk = 0
if a[1] == b[1] == c[1]:
	sk = issort(int(a[0]), int(b[0]), int(c[0]))
elif a[1] == b[1]:
	if abs(int(a[0]) - int(b[0])) == 1 or abs(int(a[0]) - int(b[0])) == 2:
		sk = 1
	else:
		sk = 2
elif c[1] == b[1]:
	if abs(int(c[0]) - int(b[0])) == 1 or abs(int(c[0]) - int(b[0])) == 2:
		sk = 1
	else:
		sk = 2
elif a[1] == c[1]:
	if abs(int(a[0]) - int(c[0])) == 1 or abs(int(a[0]) - int(c[0])) == 2:
		sk = 1
	else:
		sk = 2
else:
	sk = 2
print(min(rk, sk))


a = list(input().split())
k = dict()
mk = 0
s = 0
for e in a:
	if e not in k:
		k[e] = 0
	k[e] += 1
	if k[e] > mk:
		mk = k[e]
for e in a:
	temp = 1
	num = int(e[0])
	t = e[1]
	if str(num + 1) + t in k:
		temp += 1
		if str(num - 1) + t in k:
			temp += 1
	elif str(num - 1) + t in k:
		temp += 1
		if str(num + 1) + t in k:
			temp += 1
	elif str(num - 2) + t in k:
		temp += 1
	elif str(num + 2) + t in k:
		temp += 1
	if temp > s:
		s = temp
if s > mk:
	print(3 - s)
else:
	print(3 - mk)


(a, b, c) = map(str, input().split())
a = a[1] + a[0]
b = b[1] + b[0]
c = c[1] + c[0]
n = [a, b, c]
m = [0] * 9
p = [0] * 9
s = [0] * 9
for i in range(3):
	if n[i][0] == 'm':
		m[int(n[i][1]) - 1] += 1
	if n[i][0] == 'p':
		p[int(n[i][1]) - 1] += 1
	if n[i][0] == 's':
		s[int(n[i][1]) - 1] += 1
ans = 2
for i in range(9):
	if 3 - m[i] < ans:
		ans = 3 - m[i]
	if 0 < i and i < 8:
		if 3 - min(1, m[i - 1]) - min(1, m[i]) - min(1, m[i + 1]) < ans:
			ans = 3 - min(1, m[i - 1]) - min(1, m[i]) - min(1, m[i + 1])
	if 3 - s[i] < ans:
		ans = 3 - s[i]
	if 0 < i and i < 8:
		if 3 - min(1, s[i - 1]) - min(1, s[i]) - min(1, s[i + 1]) < ans:
			ans = 3 - min(1, s[i - 1]) - min(1, s[i]) - min(1, s[i + 1])
	if 3 - p[i] < ans:
		ans = 3 - p[i]
	if 0 < i and i < 8:
		if 3 - min(1, p[i - 1]) - min(1, p[i]) - min(1, p[i + 1]) < ans:
			ans = 3 - min(1, p[i - 1]) - min(1, p[i]) - min(1, p[i + 1])
print(ans)


from collections import Counter
s = input().split()
c = Counter(s)
mini = max(list(c.values()))
if max(list(c.values())) >= 3:
	print(0)
else:
	(su, m, p) = ([], [], [])
	for i in s:
		if i[1] == 'p':
			p.append(int(i[0]))
		elif i[1] == 's':
			su.append(int(i[0]))
		else:
			m.append(int(i[0]))
	su.sort()
	m.sort()
	p.sort()
	(c11, c1, c2, c3) = (0, 0, 0, 0)
	for j in range(len(su) - 1):
		if su[j + 1] - su[j] == 1:
			c1 = c1 + 1
		if su[j + 1] - su[j] == 2:
			c11 += 1
	for j in range(len(m) - 1):
		if m[j + 1] - m[j] == 1:
			c2 += 1
		if m[j + 1] - m[j] == 2:
			c11 += 1
	for j in range(len(p) - 1):
		if p[j + 1] - p[j] == 1:
			c3 += 1
		if p[j + 1] - p[j] == 2:
			c11 += 1
	if c1 > 1 or c2 > 1 or c3 > 1:
		print(0)
	elif c1 == 1 or c2 == 1 or c3 == 1 or (c11 > 0):
		print(1)
	else:
		print(min(3 - mini, 2))


(a, b, c) = input().split()
d = {'m': [], 'p': [], 's': []}
d[a[1]].append(int(a[0]))
d[b[1]].append(int(b[0]))
d[c[1]].append(int(c[0]))
l = ['m', 'p', 's']
ans = 2
for i in l:
	if d[i] == []:
		continue
	for j in range(1, 10):
		ans = min(ans, 3 - d[i].count(j))
	if ans < 0:
		ans = 0
	if ans == 0:
		break
	for j in range(1, 8):
		if j in d[i] and j + 1 in d[i] and (j + 2 in d[i]):
			ans = 0
		if ans == 0:
			break
		if j in d[i] and j + 1 in d[i] and (j + 2 not in d[i]):
			ans = 1
		if j in d[i] and j + 2 in d[i] and (j + 1 not in d[i]):
			ans = 1
		if j not in d[i] and j + 1 in d[i] and (j + 2 in d[i]):
			ans = 1
	if ans == 0:
		break
print(ans)


(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 arr[1] - arr[0] == 1 and arr[2] - arr[1] == 1:
			print(0)
			sys.exit()
		if arr[1] - arr[0] == 1 or arr[1] - arr[0] == 2 or arr[1] - arr[0] == 0:
			print(1)
			sys.exit()
		if arr[2] - arr[1] == 1 or arr[2] - arr[1] == 2 or arr[2] - arr[1] == 0:
			print(1)
			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 or abs(x - y) == 0:
				print(1)
				sys.exit()
			else:
				print(2)
				sys.exit()
		if b[1] == c[1]:
			if abs(y - z) == 1 or abs(y - z) == 2 or abs(y - z) == 0:
				print(1)
				sys.exit()
			else:
				print(2)
				sys.exit()
		if a[1] == c[1]:
			if abs(x - z) == 1 or abs(x - z) == 2 or abs(x - z) == 0:
				print(1)
				sys.exit()
			else:
				print(2)
				sys.exit()
		else:
			print(2)
			sys.exit()
	else:
		print(2)
		sys.exit()


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]
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)
		elif tmnl[1] == tmnl[0] + 2 or tmnl[2] == tmnl[1] + 2 or tmnl[2] == tmnl[0] + 2:
			print(1)
		else:
			print(2)
elif sl[0] == sl[1]:
	if nl[0] == nl[1]:
		print(1)
	elif abs(nl[0] - nl[1]) == 1 or abs(nl[0] - nl[1]) == 2:
		print(1)
	else:
		print(2)
elif sl[1] == sl[2]:
	if nl[1] == nl[2]:
		print(1)
	elif abs(nl[1] - nl[2]) == 1 or abs(nl[1] - nl[2]) == 2:
		print(1)
	else:
		print(2)
elif nl[0] == nl[2]:
	print(1)
elif abs(nl[0] - nl[2]) == 1 or abs(nl[0] - nl[2]) == 2:
	print(1)
else:
	print(2)


t = input()
a = t[0] + t[1]
b = t[3] + t[4]
c = t[6] + t[7]
d = {'m': t.count('m'), 'p': t.count('p'), 's': t.count('s')}
if d['m'] == 0:
	d.pop('m')
if d['p'] == 0:
	d.pop('p')
if d['s'] == 0:
	d.pop('s')
l = list()
if len(d) == 1:
	a_n = int(a[0])
	b_n = int(b[0])
	c_n = int(c[0])
	l = [a_n, b_n, c_n]
	l.sort()
	if a_n == b_n and a_n == c_n:
		print(0)
	elif a_n == b_n or a_n == c_n or b_n == c_n:
		print(1)
	elif l[0] == l[1] - 1 and l[1] == l[2] - 1:
		print(0)
	elif l[0] == l[1] - 1 or l[1] == l[2] - 1 or l[0] == l[2] - 1:
		print(1)
	elif l[0] == l[1] - 2 or l[1] == l[2] - 2 or l[0] == l[2] - 1:
		print(1)
	else:
		print(2)
elif len(d) == 2:
	x = max(d.values())
	if 'm' in d and d['m'] == x:
		x = 'm'
	elif 'p' in d and d['p'] == x:
		x = 'p'
	else:
		x = 's'
	if a[1] == x:
		l.append(int(a[0]))
	if b[1] == x:
		l.append(int(b[0]))
	if c[1] == x:
		l.append(int(c[0]))
	l.sort()
	if l[0] == l[1]:
		print(1)
	elif l[0] == l[1] - 2:
		print(1)
	elif l[0] == l[1] - 1:
		print(1)
	else:
		print(2)
else:
	print(2)


def get_min_draw(d):
	symbols = list(d.keys())
	min_draw = 3
	for key in symbols:
		for i in range(1, 8):
			curr = 3
			if i in d[key]:
				curr -= 1
			if i + 1 in d[key]:
				curr -= 1
			if i + 2 in d[key]:
				curr -= 1
			min_draw = min(min_draw, curr)
	return min_draw
arr = [i for i in input().split()]
d = {}
d2 = {}
for [num, symbol] in arr:
	num = int(num)
	if symbol not in d:
		d[symbol] = set()
	d[symbol].add(num)
	if f'{num}{symbol}' not in d2:
		d2[f'{num}{symbol}'] = 0
	d2[f'{num}{symbol}'] += 1
d2_val = max(0, 3 - max(d2.values()))
print(min(d2_val, get_min_draw(d)))


l = list(map(str, input().split()))
p = []
s = []
m = []
for i in range(3):
	if l[i][1] == 's':
		s.append(int(l[i][0]))
	if l[i][1] == 'p':
		p.append(int(l[i][0]))
	if l[i][1] == 'm':
		m.append(int(l[i][0]))
ans = 2
m.sort()
p.sort()
s.sort()
for i in range(3):
	m.append(0)
	s.append(0)
	p.append(0)
if len(p) >= 3:
	if p[0] != 0 and p[1] != 0:
		if p[0] == p[1] and p[1] == p[2]:
			ans = 0
		elif p[0] == p[1] or p[1] == p[2]:
			ans = min(ans, 1)
		elif p[1] - p[0] == 1 and p[2] - p[1] == 1:
			ans = 0
		elif p[1] - p[0] == 1 or p[2] - p[1] == 1:
			ans = min(ans, 1)
		elif p[1] - p[0] == 2 or (p[2] != 0 and p[2] - p[1] == 2):
			ans = min(ans, 1)
if len(s) >= 3:
	if s[0] != 0 and s[1] != 0:
		if s[0] == s[1] and s[1] == s[2]:
			ans = 0
		elif s[0] == s[1] or s[1] == s[2]:
			ans = min(ans, 1)
		elif s[1] - s[0] == 1 and s[2] - s[1] == 1:
			ans = 0
		elif s[1] - s[0] == 1 or s[2] - s[1] == 1:
			ans = min(ans, 1)
		elif s[1] - s[0] == 2 or (s[2] != 0 and s[2] - s[1] == 2):
			ans = min(ans, 1)
if len(m) >= 3:
	if m[0] != 0 and m[1] != 0:
		if m[0] == m[1] and m[1] == m[2]:
			ans = 0
		elif m[0] == m[1] or m[1] == m[2]:
			ans = min(ans, 1)
		elif m[1] - m[0] == 1 and m[2] - m[1] == 1:
			ans = 0
		elif m[1] - m[0] == 1 or m[2] - m[1] == 1:
			ans = min(ans, 1)
		elif m[1] - m[0] == 2 or (m[2] != 0 and m[2] - m[1] == 2):
			ans = min(ans, 1)
print(ans)


t = input().split()
t.sort()
if t.count(t[0]) == 3:
	print('0')
elif t.count(t[0]) == 2 or t.count(t[1]) == 2:
	print('1')
else:
	num = list(map(int, [t[0][0], t[1][0], t[2][0]]))
	suit = [t[0][1], t[1][1], t[2][1]]
	if len(set(suit)) == 3:
		print('2')
	elif len(set(suit)) == 1:
		if num[1] == num[0] + 1 or num[2] == num[1] + 1:
			if num[2] == num[0] + 2:
				print('0')
			else:
				print('1')
		elif num[1] == num[0] + 2 or num[2] == num[1] + 2:
			print('1')
		else:
			print('2')
	elif suit[0] == suit[1]:
		if num[1] - num[0] in [1, 2]:
			print('1')
		else:
			print('2')
	elif suit[1] == suit[2]:
		if num[2] - num[1] in [1, 2]:
			print('1')
		else:
			print('2')
	elif num[2] - num[0] in [1, 2]:
		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)


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
options = {x: [0] * 9 for x in 'smp'}
for x in input().split():
	options[x[1]][int(x[0]) - 1] += 1
ans = 2
for c in 'smp':
	curr = options[c]
	if max(curr) >= 2:
		ans = min(ans, 3 - max(curr))
	else:
		for i in range(7):
			sums = sum(curr[i:i + 3])
			ans = min(ans, 3 - sums)
print(ans)


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
	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)


(t1, t2, t3) = map(str, input().split())
m = []
s = []
p = []
if t1[1] == 'm':
	m.append(int(t1[0]))
elif t1[1] == 's':
	s.append(int(t1[0]))
else:
	p.append(int(t1[0]))
if t2[1] == 'm':
	m.append(int(t2[0]))
elif t2[1] == 's':
	s.append(int(t2[0]))
else:
	p.append(int(t2[0]))
if t3[1] == 'm':
	m.append(int(t3[0]))
elif t3[1] == 's':
	s.append(int(t3[0]))
else:
	p.append(int(t3[0]))
m.sort()
s.sort()
p.sort()
if len(m) == 0:
	ans_m = 3
elif len(m) == 1:
	ans_m = 2
elif len(m) == 2:
	if m[0] == m[1] or m[1] == m[0] + 1 or m[1] == m[0] + 2:
		ans_m = 1
	else:
		ans_m = 2
elif m[0] == m[1] == m[2] or (m[1] == m[0] + 1 and m[2] == m[1] + 1):
	ans_m = 0
elif m[0] == m[1] or m[1] == m[2] or m[0] == m[2] or (m[1] == m[0] + 1) or (m[2] == m[1] + 1) or (m[1] == m[0] + 2) or (m[2] == m[1] + 2):
	ans_m = 1
else:
	ans_m = 2
if len(s) == 0:
	ans_s = 3
elif len(s) == 1:
	ans_s = 2
elif len(s) == 2:
	if s[0] == s[1] or s[1] == s[0] + 1 or s[1] == s[0] + 2:
		ans_s = 1
	else:
		ans_s = 2
elif s[0] == s[1] == s[2] or (s[1] == s[0] + 1 and s[2] == s[1] + 1):
	ans_s = 0
elif s[0] == s[1] or s[1] == s[2] or s[0] == s[2] or (s[1] == s[0] + 1) or (s[2] == s[1] + 1) or (s[1] == s[0] + 2) or (s[2] == s[1] + 2):
	ans_s = 1
else:
	ans_s = 2
if len(p) == 0:
	ans_p = 3
elif len(p) == 1:
	ans_p = 2
elif len(p) == 2:
	if p[0] == p[1] or p[1] == p[0] + 1 or p[1] == p[0] + 2:
		ans_p = 1
	else:
		ans_p = 2
elif p[0] == p[1] == p[2] or (p[1] == p[0] + 1 and p[2] == p[1] + 1):
	ans_p = 0
elif p[0] == p[1] or p[1] == p[2] or p[0] == p[2] or (p[1] == p[0] + 1) or (p[2] == p[1] + 1) or (p[1] == p[0] + 2) or (p[2] == p[1] + 2):
	ans_p = 1
else:
	ans_p = 2
print(min(ans_m, ans_s, ans_p))


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


s = [0] * 10
m = [0] * 10
p = [0] * 10
D = list(input().split())
for i in D:
	if i[1] == 'p':
		p[int(i[0])] += 1
	elif i[1] == 'm':
		m[int(i[0])] += 1
	else:
		s[int(i[0])] += 1
need = 3
for i in range(1, 10):
	need = min(3 - p[i], need)
	need = min(3 - s[i], need)
	need = min(3 - m[i], need)
	if i <= 7:
		tmp = 0
		tmp += min(1, p[i])
		tmp += min(1, p[i + 1])
		tmp += min(1, p[i + 2])
		need = min(3 - tmp, need)
		tmp = 0
		tmp += min(1, m[i])
		tmp += min(1, m[i + 1])
		tmp += min(1, m[i + 2])
		need = min(3 - tmp, need)
		tmp = 0
		tmp += min(1, s[i])
		tmp += min(1, s[i + 1])
		tmp += min(1, s[i + 2])
		need = min(3 - tmp, need)
print(need)


s = input()
p1 = s[0:2]
p2 = s[3:5]
p3 = s[6:8]
dict1 = {}
dict1[p1[1]] = 0
dict1[p2[1]] = 0
dict1[p3[1]] = 0
dict1[p1[1]] += 1
dict1[p2[1]] += 1
dict1[p3[1]] += 1
a1 = int(p1[0])
a2 = int(p2[0])
a3 = int(p3[0])
l = []
l.append(a1)
l.append(a2)
l.append(a3)
l.sort()
if len(dict1) == 1:
	if p1[0] == p2[0] and p2[0] == p3[0] or (abs(l[0] - l[1]) == 1 and abs(l[1] - l[2]) == 1):
		print(0)
	elif abs(a1 - a2) == 0 or abs(a1 - a2) == 1 or abs(a1 - a2) == 2 or (abs(a1 - a3) == 0) or (abs(a1 - a3) == 1) or (abs(a1 - a3) == 2) or (abs(a3 - a2) == 0) or (abs(a3 - a2) == 1) or (abs(a3 - a2) == 2):
		print(1)
	else:
		print(2)
elif len(dict1) == 3:
	print(2)
elif p1[1] == p2[1]:
	if abs(a1 - a2) == 1 or abs(a1 - a2) == 0 or abs(a1 - a2) == 2:
		print(1)
	else:
		print(2)
elif p1[1] == p3[1]:
	if abs(a1 - a3) == 1 or abs(a1 - a3) == 0 or abs(a1 - a3) == 2:
		print(1)
	else:
		print(2)
elif p2[1] == p3[1]:
	if abs(a2 - a3) == 1 or abs(a2 - a3) == 0 or abs(a2 - a3) == 2:
		print(1)
	else:
		print(2)


s = list(map(str, input().split()))
arr = []
for i in range(3):
	arr.append([])
d = {}
for i in s:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
	if i[1] == 'm':
		arr[0].append(int(i[0]))
	elif i[1] == 'p':
		arr[1].append(int(i[0]))
	else:
		arr[2].append(int(i[0]))
ans = len(d) - 1
for i in range(3):
	b = set()
	for j in arr[i]:
		b.add(j)
	b = list(b)
	b.sort()
	for j in range(1, len(b)):
		if b[j] - b[j - 1] == 1:
			ans = min(ans, 1)
	for j in range(1, len(b)):
		if b[j] - b[j - 1] == 2:
			ans = min(ans, 1)
	for j in range(2, len(b)):
		if b[j] - b[j - 1] == 1 and b[j - 1] - b[j - 2] == 1:
			ans = 0
print(ans)


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)


import sys
from collections import defaultdict as dc
from bisect import bisect_left, bisect_right
l = list(input().split())
x = []
y = dc(int)
for i in range(3):
	y[l[i]] += 1
	x.append(list(l[i]))
if 3 in y.values():
	print(0)
elif 2 in y.values():
	print(1)
else:
	x.sort(key=lambda x: (x[1], x[0]))
	f = 1
	i = 1
	c = 0
	f1 = 0
	while i < 3 and f:
		if int(x[i][0]) - int(x[i - 1][0]) == 1 and x[i][1] == x[i - 1][1]:
			i += 1
			c += 1
		elif int(x[i][0]) - int(x[i - 1][0]) == 2 and x[i][1] == x[i - 1][1]:
			f1 = 1
			i += 1
		else:
			i += 1
	if c == 2:
		print(0)
	elif f1 == 1:
		print(1)
	elif c == 0:
		print(2)
	else:
		print(1)


a = [[], [], []]
s = input().split(' ')
for i in range(len(s)):
	if s[i][1] == 'm':
		a[0].append(int(s[i][0]))
	elif s[i][1] == 'p':
		a[1].append(int(s[i][0]))
	else:
		a[2].append(int(s[i][0]))
ko = 10
for i in range(len(a)):
	a[i] = sorted(a[i])
	c = 0
	for j in range(1, len(a[i])):
		if a[i][j] == a[i][j - 1]:
			c += 1
	if c == 1:
		ko = min(ko, 1)
	elif c == 2:
		ko = min(ko, 0)
	elif len(a[i]) > 0:
		ko = min(ko, 2)
ans = ko
ko = 10
for i in range(len(a)):
	a[i] = sorted(a[i])
	c = 0
	for j in range(1, len(a[i])):
		if a[i][j] == a[i][j - 1] + 1:
			c += 1
	if c == 1:
		ko = min(ko, 1)
	elif c == 2:
		ko = min(ko, 0)
	elif len(a[i]) > 1 and a[i][0] + 2 == a[i][1]:
		ko = min(ko, 1)
	elif len(a[i]) > 2 and a[i][1] + 2 == a[i][2]:
		ko = min(ko, 1)
	elif len(a[i]) > 0:
		ko = min(ko, 2)
print(min(ans, ko))


from sys import stdin, stdout, setrecursionlimit
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
from collections import defaultdict as dd
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def def_value():
	return 0
a = list(smp())
a.sort()
if a[0] == a[1] and a[1] == a[2]:
	print(0)
elif a[0] == a[2] or a[0] == a[1] or a[1] == a[2]:
	print(1)
elif a[0][1] == a[1][1] and 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][1] == a[1][1] and (int(a[0][0]) + 1 == int(a[1][0]) or int(a[0][0]) + 2 == int(a[1][0])):
	print(1)
elif a[0][1] == a[2][1] and (int(a[0][0]) + 1 == int(a[2][0]) or int(a[0][0]) + 2 == int(a[2][0])):
	print(1)
elif a[1][1] == a[2][1] and (int(a[1][0]) + 1 == int(a[2][0]) or int(a[1][0]) + 2 == int(a[2][0])):
	print(1)
else:
	print(2)


(a, b, c) = map(str, input().split())
l = [int(a[0]), int(b[0]), int(c[0])]
l.sort()
if a == b and b == c:
	print(0)
elif a == b or a == c or b == c:
	print(1)
elif a[1] == b[1] and b[1] == c[1]:
	if l[2] == l[1] + 1 and l[1] == l[0] + 1:
		print(0)
	elif l[1] == l[0] + 1 or l[2] == l[1] + 1 or l[2] == l[0] + 2 or (l[1] == l[0] + 2) or (l[2] == l[1] + 2):
		print(1)
	else:
		print(2)
elif a[1] == b[1] or b[1] == c[1] or a[1] == c[1]:
	if a[1] == b[1]:
		if int(abs(int(a[0]) - int(b[0]))) <= 2:
			print(1)
		else:
			print(2)
	if a[1] == c[1]:
		if int(abs(int(a[0]) - int(c[0]))) <= 2:
			print(1)
		else:
			print(2)
	if b[1] == c[1]:
		if int(abs(int(b[0]) - int(c[0]))) <= 2:
			print(1)
		else:
			print(2)
else:
	print(2)


s = input()
arr = list(s.split())
a = [0] * 10
b = [0] * 10
c = [0] * 10
for ch in arr:
	num = int(ch[0])
	ch = ch[1]
	if ch == 'm':
		a[num] += 1
	elif ch == 'p':
		b[num] += 1
	else:
		c[num] += 1
ans = 3
for i in range(1, 10):
	ans = min(ans, 3 - a[i])
	if i + 1 < 10:
		ans = min(ans, 3 - min(1, a[i]) - min(1, a[i + 1]))
	if i + 2 < 10:
		ans = min(ans, 3 - min(1, a[i]) - min(1, a[i + 1]) - min(1, a[i + 2]))
for i in range(1, 10):
	ans = min(ans, 3 - b[i])
	if i + 1 < 10:
		ans = min(ans, 3 - min(1, b[i]) - min(1, b[i + 1]))
	if i + 2 < 10:
		ans = min(ans, 3 - min(1, b[i]) - min(1, b[i + 1]) - min(1, b[i + 2]))
for i in range(1, 10):
	ans = min(ans, 3 - c[i])
	if i + 1 < 10:
		ans = min(ans, 3 - min(1, c[i]) - min(1, c[i + 1]))
	if i + 2 < 10:
		ans = min(ans, 3 - min(1, c[i]) - min(1, c[i + 1]) - min(1, c[i + 2]))
print(ans)


a = input().split()
count = [0, 0, 0]
alp = ['m', 'p', 's']
for i in range(3):
	if a[i][1] == 'm':
		count[0] += 1
	elif a[i][1] == 'p':
		count[1] += 1
	else:
		count[2] += 1
if max(count) == 3:
	d = [0, 0, 0]
	d[0] = abs(int(a[0][0]) - int(a[1][0]))
	d[1] = abs(int(a[0][0]) - int(a[2][0]))
	d[2] = abs(int(a[1][0]) - int(a[2][0]))
	d.sort()
	if d[0] <= 2:
		if d == [0, 0, 0]:
			print(0)
		elif d == [1, 1, 2]:
			print(0)
		else:
			print(1)
	else:
		print(2)
elif max(count) == 2:
	i = 0
	l = [0, 0]
	while i < 3:
		if count[i] == 2:
			break
		i += 1
	ct = 0
	for j in range(3):
		if a[j][1] == alp[i]:
			l[ct] = int(a[j][0])
			ct += 1
	if abs(l[0] - l[1]) <= 2:
		print(1)
	else:
		print(2)
else:
	print(2)


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
			elif 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))


m = {'m': [0] * 9, 's': [0] * 9, 'p': [0] * 9}
for s in input().split():
	m[s[1]][int(s[0]) - 1] += 1
ans = 2
for c in 'smp':
	l = m[c]
	if max(l) >= 2:
		ans = min(ans, 3 - max(l))
	else:
		for i in range(7):
			sm = sum(l[i:i + 3])
			ans = min(ans, 3 - sm)
print(ans)


s = {}
s['s'] = []
s['m'] = []
s['p'] = []
a = input()
h = a[0:2]
s[h[1]].append(int(h[0]))
h = a[3:5]
s[h[1]].append(int(h[0]))
h = a[6:8]
s[h[1]].append(int(h[0]))
s['s'].sort()
s['m'].sort()
s['p'].sort()
if len(s['s']) == 1 and len(s['p']) == 1:
	print('2')
for x in s:
	if len(s[x]) == 2:
		if s[x][1] - s[x][0] == 0 or s[x][1] - s[x][0] == 1 or s[x][1] - s[x][0] == 2:
			print('1')
		else:
			print('2')
		break
	elif len(s[x]) == 3:
		a = [s[x][1] - s[x][0], s[x][2] - s[x][1]]
		if a[0] == 0 and a[1] == 0 or (a[0] == 1 and a[1] == 1):
			print('0')
		elif a[0] == 0 or a[0] == 1 or a[0] == 2 or (a[1] == 0) or (a[1] == 1) or (a[1] == 2):
			print('1')
		else:
			print('2')
		break


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)
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)))


import sys
tiles = sys.stdin.read().split()
numbers = [int(tile[0]) for tile in tiles]
letters = [tile[1] for tile in tiles]

def two(i1, i2):
	if numbers[i1] == numbers[i2]:
		return 1
	difference = abs(numbers[i1] - numbers[i2])
	if difference == 1 or difference == 2:
		return 1
	return 2

def solve():
	if letters[0] == letters[1] == letters[2]:
		if numbers[0] == numbers[1] == numbers[2]:
			return 0
		numbers.sort()
		if numbers[0] == numbers[1] - 1 == numbers[2] - 2:
			return 0
		return min(two(0, 1), two(1, 2))
	elif letters[0] == letters[1]:
		return two(0, 1)
	elif letters[1] == letters[2]:
		return two(1, 2)
	elif letters[0] == letters[2]:
		return two(0, 2)
	return 2
print(solve())


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

def check(a, b, c):
	if a == b == c:
		return True
	if a[1] == b[1] == c[1]:
		a = int(a[0])
		b = int(b[0])
		c = int(c[0])
		x = [a, b, c]
		x.sort()
		if x[1] == x[0] + 1 and x[2] == x[1] + 1:
			return True
	return False
s = []
for i in range(1, 10):
	for cc in ['m', 's', 'p']:
		s.append(str(i) + cc)
if check(a, b, c):
	print(0)
	quit()
cur = [a, b, c]
for r1 in [a, b, c]:
	cur.remove(r1)
	for n1 in s:
		cur.append(n1)
		if check(*cur):
			print(1)
			quit()
		cur.remove(n1)
	cur.append(r1)
print(2)


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)


l = list(input().split(' '))
d = {}
d['m'] = []
d['p'] = []
d['s'] = []
q = []
for i in l:
	if i[1] == 'm':
		d['m'].append(int(i[0]))
	elif i[1] == 'p':
		d['p'].append(int(i[0]))
	else:
		d['s'].append(int(i[0]))
ma = 0
e = ''
for i in d:
	if len(d[i]) >= ma:
		ma = len(d[i])
		e = i
if len(d[e]) == 1:
	print(2)
elif len(d[e]) == 2:
	if abs(d[e][0] - d[e][1]) == 1 or abs(d[e][0] - d[e][1]) == 0 or abs(d[e][0] - d[e][1]) == 2:
		print(1)
	else:
		print(2)
else:
	d[e].sort()
	f = []
	f.append(d[e][0] - d[e][1])
	f.append(d[e][1] - d[e][2])
	f.append(d[e][0] - d[e][2])
	if f.count(0) == 3 or (f.count(-1) == 2 and f.count(-2) == 1):
		print(0)
	elif f.count(0) == 1 or f.count(-1) == 1 or f.count(-2) > 0:
		print(1)
	else:
		print(2)


def checkConsecutive(l):
	return sorted(l) == list(range(min(l), max(l) + 1))
(a, b, c) = map(str, input().split())
(x, y, z) = (int(a[0]), int(b[0]), int(c[0]))
(p, q, r) = (a[1], b[1], c[1])
l = []
l.append(x)
l.append(y)
l.append(z)
if a == b == c or (checkConsecutive(l) and p == q == r):
	ans = 0
elif (x == y + 1 or x == y + 2) and p == q or ((y == z + 1 or y == z + 2) and q == r) or ((z == x + 1 or z == x + 2) and p == r) or ((x == z + 1 or x == z + 2) and p == r) or ((y == x + 1 or y == x + 2) and q == p) or ((z == y + 1 or z == y + 2) and q == r):
	ans = 1
elif a == b or b == c or a == c:
	ans = 1
else:
	ans = 2
print(ans)


a = sorted(input().split())
r = len({*a}) - 1
a = sorted(a, key=lambda x: (x[1], x[0]))
(v, s) = [*zip(*a)]
c = 1
for i in range(1, 3):
	if s[i] == s[i - 1] and int(v[i - 1]) + 1 == int(v[i]):
		c += 1
		r = min(r, 3 - c)
	elif s[i] == s[i - 1] and int(v[i - 1]) + 2 == int(v[i]):
		r = min(r, 1)
	else:
		c = 1
print(r)


def p(s, n):
	return str(int(s[0]) + n) + s[1]
(a, b, c) = sorted(input().split(), key=lambda x: int(x[0]))
if a == b == c or (a == p(b, -1) and c == p(b, 1)):
	print(0)
elif a == b or b == c or a == c:
	print(1)
elif p(a, 1) in [b, c] or p(a, 2) in [b, c] or p(a, -1) in [b, c] or (p(a, -2) in [b, c]):
	print(1)
elif p(b, 1) in [a, c] or p(b, 2) in [a, c] or p(b, -1) in [a, c] or (p(b, -2) in [a, c]):
	print(1)
elif p(c, 1) in [b, a] or p(c, 2) in [b, a] or p(c, -1) in [b, a] or (p(c, -2) in [b, a]):
	print(1)
else:
	print(2)


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


from collections import defaultdict
st = input()
st2 = st.replace(' ', '')
g = defaultdict(list)
for x in range(0, 7):
	if x % 2 == 1:
		g[st2[x]].append(int(st2[x - 1]))
for x in g:
	g[x].sort()
if len(g) == 3:
	print(2)
elif len(g) == 2:
	for x in g:
		if len(g[x]) == 2:
			if g[x][0] == g[x][1] or abs(g[x][0] - g[x][1]) == 1 or abs(g[x][0] - g[x][1]) == 2:
				print(1)
			else:
				print(2)
elif len(g) == 1:
	for x in g:
		if g[x][0] == g[x][1] == g[x][2] or (abs(g[x][0] - g[x][1]) == 1 and abs(g[x][1] - g[x][2]) == 1):
			print(0)
		elif abs(g[x][0] - g[x][1]) > 2 and abs(g[x][1] - g[x][2]) > 2:
			print(2)
		else:
			print(1)


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)


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
		elif diff(t[0][0], t[1][0]) == 2:
			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
		elif diff(x[0], y[0]) == 2 or diff(x[0], z[0]) == 2 or diff(y[0], z[0]) == 2:
			p = 1
		else:
			p = 2
print(p)


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:
	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
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)


a = sorted((10 * ord(x[1]) + int(x[0]) for x in input().split()))
s = {a[1] - a[0], a[2] - a[1]}
print(2 - bool(s & {0, 1, 2}) - (s in ({0}, {1})))


import math as mt
import sys, string, bisect
input = sys.stdin.readline
l = list(input().split())
s = set(l)
for i in s:
	if l.count(i) == 3:
		print(0)
		exit()
	elif l.count(i) == 2:
		print(1)
		exit()
else:
	g = []
	for i in range(3):
		g.append((l[i][0], l[i][1]))
	g.sort(key=lambda x: x[0])
	if int(g[2][0]) - int(g[1][0]) == 1 and int(g[1][0]) - int(g[0][0]) == 1 and (g[0][1] == g[1][1]) and (g[1][1] == g[2][1]):
		print(0)
		exit()
	if int(g[2][0]) - int(g[1][0]) == 1 and g[1][1] == g[2][1]:
		print(1)
		exit()
	if int(g[2][0]) - int(g[0][0]) == 1 and g[0][1] == g[2][1]:
		print(1)
		exit()
	if int(g[1][0]) - int(g[0][0]) == 1 and g[0][1] == g[1][1]:
		print(1)
		exit()
	else:
		if int(g[2][0]) - int(g[0][0]) == 2 and g[2][1] == g[0][1]:
			print(1)
			exit()
		if int(g[2][0]) - int(g[1][0]) == 2 and g[2][1] == g[1][1]:
			print(1)
			exit()
		if int(g[1][0]) - int(g[0][0]) == 2 and g[1][1] == g[0][1]:
			print(1)
			exit()
		else:
			print(2)
			exit()


from sys import stdin, stdout, exit
(t1, t2, t3) = stdin.readline().split()
if t1 == t2 and t2 == t3:
	print(0)
	exit()
ts = [(int(t[0]), t[1]) for t in [t1, t2, t3]]
ts.sort()
ns = [t[0] for t in ts]
ss = [t[1] for t in ts]
if ns[0] + 1 == ns[1] and ns[0] + 2 == ns[2] and (ss[0] == ss[1]) and (ss[1] == ss[2]):
	print(0)
	exit()
if ns[0] + 2 >= ns[1] and ss[1] == ss[0]:
	print(1)
	exit()
if ns[1] + 2 >= ns[2] and ss[1] == ss[2]:
	print(1)
	exit()
if ns[0] + 2 >= ns[2] and ss[0] == ss[2]:
	print(1)
	exit()
if ts[0] == ts[1] or ts[1] == ts[2] or ts[2] == ts[0]:
	print(1)
	exit()
print(2)


from sys import stdin
s = stdin.readline().strip().split()
s1 = []
for i in s:
	s1.append([int(i[0]), i[1]])
aux1 = 0
for i in range(3):
	aux = 0
	for j in range(3):
		if s[i] == s[j]:
			aux += 1
	aux1 = max(aux1, aux)
aux2 = 0
for i in range(3):
	st = set()
	for j in range(3):
		if s[i][1] == s[j][1] and abs(int(s[i][0]) - int(s[j][0])) <= 2:
			st.add(int(s[j][0]))
	arr = list(st)
	arr.sort()
	if abs(arr[0] - arr[-1]) > 2:
		st.remove(arr[0])
	aux2 = max(len(st), aux2)
print(min(3 - aux1, 3 - aux2))


def check(aa):
	a = [i for i in aa]
	b = a[:]
	b.sort()
	ans1 = 100
	c = [int(i[0]) for i in a]
	for i in range(3):
		m = 10 ** 12
		for j in range(3):
			if c[i] - 2 + j >= 0:
				d = []
				d.append(str(c[i] - 2 + j) + a[i][1])
				d.append(str(c[i] - 1 + j) + a[i][1])
				d.append(str(c[i] + j) + a[i][1])
				d.sort()
				ans = 0
				for k in d:
					if k not in b:
						ans += 1
						if int(k[0]) < 1 or int(k[0]) > 9:
							ans = 500
				ans1 = min(ans, ans1)
	d1 = [a[0][0] + a[0][1], a[0][0] + a[0][1], a[0][0] + a[0][1]]
	d2 = [a[1][0] + a[1][1], a[1][0] + a[1][1], a[1][0] + a[1][1]]
	d3 = [a[2][0] + a[2][1], a[2][0] + a[2][1], a[2][0] + a[2][1]]
	dd = [d1, d2, d3]
	ddd = {}
	for i in a:
		ddd[i] = ddd.get(i, 0) + 1
	for i in dd:
		ans = 0
		d4 = ddd.copy()
		for j in i:
			if d4[j] > 0:
				d4[j] -= 1
			else:
				ans += 1
		ans1 = min(ans1, ans)
	return ans1
(a, b, c) = map(str, input().split())
print(check([a, b, c]))


ll = lambda : list(map(int, input().split()))
testcases = 1
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:
						ans = 1
						break
			if ans == 1:
				break
		print(ans)
	else:
		print(2)


from operator import itemgetter
A = [[int(a[0]), a[1]] for a in list(map(str, input().split()))]
D = {}
for a in A:
	if not a[1] in D.keys():
		D[a[1]] = [a[0]]
	else:
		D[a[1]].append(a[0])
ans = 2
for d in D.values():
	if len(d) == 1:
		continue
	elif len(d) == 2:
		if d[0] == d[1] or abs(d[0] - d[1]) == 1 or abs(d[0] - d[1]) == 2:
			ans = min(ans, 1)
	else:
		d.sort()
		if d[0] == d[2] or (abs(d[0] - d[1]) == 1 and abs(d[2] - d[1]) == 1):
			ans = 0
		elif d[0] == d[1] or d[1] == d[2] or abs(d[0] - d[1]) == 1 or (abs(d[2] - d[1]) == 1) or (abs(d[0] - d[1]) == 2) or (abs(d[2] - d[1]) == 2):
			ans = min(ans, 1)
print(ans)


import math
from collections import deque, defaultdict
from sys import stdin, stdout
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
s = list(input().split())
z = set(s)
if len(z) == 1:
	print(0)
elif len(z) == 2:
	print(1)
else:
	counter = defaultdict(int)
	for i in s:
		counter[i[1]] += 1
	for i in counter.items():
		if i[1] == 3:
			a = []
			for j in s:
				a.append(int(j[0]))
			a.sort()
			if abs(a[0] - a[1]) == 1 and a[-1] - a[1] == 1:
				print(0)
			elif abs(a[0] - a[1]) <= 2 or abs(a[-1] - a[1]) <= 2 or abs(a[-1] - a[0]) <= 2:
				print(1)
			else:
				print(2)
			exit()
		elif i[1] == 2:
			a = []
			for j in s:
				if j[1] == i[0]:
					a.append(int(j[0]))
			if abs(a[0] - a[1]) <= 2:
				print(1)
				exit()
	print(2)


n = input().split()
init = len(n)
m = set(n)
fg = 0
final = len(m)

def checkConsecutive(l):
	return sorted(l) == list(range(min(l), max(l) + 1))
lst = []
lst.append(int(n[0][0]))
lst.append(int(n[1][0]))
lst.append(int(n[2][0]))
if n[0][1] == n[1][1] and n[1][1] == n[2][1] and checkConsecutive(lst):
	fg = 0
elif n[0][1] == n[1][1] and (abs(int(n[0][0]) - int(n[1][0])) == 1 or abs(int(n[0][0]) - int(n[1][0])) == 2):
	fg = 1
elif n[1][1] == n[2][1] and (abs(int(n[1][0]) - int(n[2][0])) == 1 or abs(int(n[1][0]) - int(n[2][0])) == 2):
	fg = 1
elif n[0][1] == n[2][1] and (abs(int(n[0][0]) - int(n[2][0])) == 1 or abs(int(n[0][0]) - int(n[2][0])) == 2):
	fg = 1
elif init - final == 1:
	fg = 1
elif init - final == 2:
	fg = 0
else:
	fg = 2
if fg == 0:
	print(0)
elif fg == 1:
	print(1)
else:
	print(2)


inp = input().split()
mps = [0, 0, 0]
k = ['m', 'p', 's']
num = []
for i in range(3):
	if inp[i][1] == k[0]:
		mps[0] += 1
	elif inp[i][1] == k[1]:
		mps[1] += 1
	else:
		mps[2] += 1
sl = max(mps)
t = mps.index(sl)
for i in range(3):
	if inp[i][1] == k[t]:
		num.append(int(inp[i][0]))
if sl == 1:
	print(2)
elif sl == 2:
	num.sort()
	kq = 0
	if num[1] - num[0] <= 2:
		kq = 1
	else:
		kq = 2
	print(kq)
else:
	num.sort()
	kq = 0
	if num[1] - num[0] == 0:
		if num[2] - num[1] <= 1:
			kq = num[2] - num[1]
		else:
			kq = 1
	elif num[1] - num[0] == 1:
		if num[2] - num[1] == 1:
			kq = 0
		else:
			kq = 1
	elif num[1] - num[0] == 2:
		kq = 1
	elif num[2] - num[1] <= 2:
		kq = 1
	else:
		kq = 2
	print(kq)


def fl(a, b):
	if a == b:
		return 1
	else:
		return 0
(a, b, c) = input().split()
l1 = [i for i in range(1, 10)]
su = 0
su += fl(a, b)
su += fl(c, b)
su += fl(a, c)
dic = {}
dic['s'] = 0
dic['m'] = 0
dic['p'] = 0
if su == 1:
	print(1)
elif su == 3:
	print(0)
else:
	dic[a[1]] += 1
	dic[b[1]] += 1
	dic[c[1]] += 1
	f = 1
	for i in dic:
		if dic[i] > 1:
			if dic[i] == 2:
				m = []
				for j in [a, b, c]:
					if j[1] == i:
						m.append(int(j[0]))
				if abs(m[0] - m[1]) <= 2:
					print(1)
				else:
					print(2)
				break
			elif dic[i] == 3:
				m = int(a[0])
				n = int(b[0])
				p = int(c[0])
				if abs(m - n) + abs(n - p) + abs(p - m) == 4:
					print(0)
				else:
					flag = 0
					if abs(m - n) <= 2:
						flag = 1
					if abs(p - n) <= 2:
						flag = 1
					if abs(m - p) <= 2:
						flag = 1
					if flag:
						print(1)
					else:
						print(2)
				break
	else:
		print(2)


data = input().split()
(z, a) = ([], [])
for i in range(3):
	a.append(int(data[i][0]))
	z.append(data[i][1])
if all((data[0] == data[i] for i in range(3))):
	print(0)
elif data[0] == data[1] or data[1] == data[2] or data[0] == data[2]:
	print(1)
else:
	k = sorted(a)
	if z[0] == z[1] == z[2] and k[0] == k[1] - 1 == k[2] - 2:
		print(0)
	elif z[0] == z[1] and abs(a[0] - a[1]) in [1, 2] or (z[1] == z[2] and abs(a[1] - a[2]) in [1, 2]) or (z[0] == z[2] and abs(a[0] - a[2]) in [1, 2]):
		print(1)
	else:
		print(2)


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 = min(r, 1)
	else:
		r = min(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
	r = 2
	a = sorted(a)
	if a[1] - a[0] == 1 or a[1] - a[0] == 2:
		r = min(r, 1)
	elif len(set(l)) == 2:
		r = min(r, 1)
	else:
		r = min(r, 2)
	print(r)


s = list(input().split())
s = sorted(s)
if len(set(s)) == 1:
	print('0')
elif s[0][1] == s[1][1] and s[1][1] == s[2][1] and (int(s[1][0]) - int(s[0][0]) == 1) and (int(s[2][0]) - int(s[1][0]) == 1):
	print('0')
elif len(set(s)) == 2:
	print('1')
elif s[0][1] == s[1][1] and (int(s[1][0]) - int(s[0][0]) == 1 or int(s[1][0]) - int(s[0][0]) == 2) or (s[1][1] == s[2][1] and (int(s[2][0]) - int(s[1][0]) == 1 or int(s[2][0]) - int(s[1][0]) == 2)) or (s[0][1] == s[2][1] and (int(s[2][0]) - int(s[0][0]) == 2 or int(s[2][0]) - int(s[0][0]) == 1)):
	print('1')
else:
	print('2')


s = input().split()
hand = {'m': [], 'p': [], 's': []}
for item in s:
	hand[item[1]].append(int(item[0]))
min_steps_needed = 10
for symb in ['m', 'p', 's']:
	hand[symb] = sorted(hand[symb])
	for start in range(1, 10):
		a_needed = 10
		b_needed = 10
		a_needed = 3 - hand[symb].count(start)
		(b1, b2, b3) = (0, 0, 0)
		if hand[symb].count(start) > 0:
			b1 = 1
		if hand[symb].count(start + 1) > 0:
			b2 = 1
		if hand[symb].count(start + 2) > 0:
			b3 = 1
		b_needed = 3 - b1 - b2 - b3
		if a_needed < min_steps_needed:
			min_steps_needed = a_needed
		if b_needed < min_steps_needed:
			min_steps_needed = b_needed
print(min_steps_needed)


l = list(input().split())
l.sort()
(a, b) = zip(*l)
a = list(map(int, a))
(x, y, z) = (len(set(a)), len(set(b)), len(set(l)))
if x == 1 and y == 1:
	print(0)
elif y == 1 and a[1] - a[0] == a[2] - a[1] == 1:
	print(0)
elif a[1] - a[0] <= 2 and b[0] == b[1] or (a[2] - a[1] <= 2 and b[1] == b[2]) or (a[2] - a[0] <= 2 and b[0] == b[2]) or (z == 2):
	print(1)
else:
	print(2)


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import *
sys.setrecursionlimit(99999)
arr = list(input().split())
arr.sort()
ans = 3
cs = collections.Counter(arr)

def check(ap):
	cp = collections.Counter(ap)
	c = 0
	for (k, v) in cs.items():
		c += min(v, cp[k])
	return 3 - c
for i in range(1, 10):
	ans = min(ans, check([str(i) + 's', str(i) + 's', str(i) + 's']))
	ans = min(ans, check([str(i) + 'p', str(i) + 'p', str(i) + 'p']))
	ans = min(ans, check([str(i) + 'm', str(i) + 'm', str(i) + 'm']))
	if i <= 7:
		ans = min(ans, check([str(i) + 's', str(i + 1) + 's', str(i + 2) + 's']))
		ans = min(ans, check([str(i) + 'p', str(i + 1) + 'p', str(i + 2) + 'p']))
		ans = min(ans, check([str(i) + 'm', str(i + 1) + 'm', str(i + 2) + 'm']))
print(ans)


d = {}
for (x, y) in input().split():
	d.setdefault(y, []).append(int(x))
r = 2
for k in d:
	a = sorted(d[k])
	s = {y - x for (x, y) in zip(a, a[1:])}
	if len(a) > 2 and s in ({0}, {1}):
		r = 0
	if {0, 1, 2} & s:
		r = min(r, 1)
print(r)


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


(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')
	elif a == b or b == c or a == c:
		print('1')
	elif 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) or (aa == bb - 2 or aa - 2 == bb)) and a[1] == b[1]:
			print('1')
		elif ((aa == cc - 1 or aa - 1 == cc) or (aa == cc - 2 or aa - 2 == cc)) and a[1] == c[1]:
			print('1')
		elif ((cc == bb - 1 or cc - 1 == bb) or (cc == bb - 2 or cc - 2 == bb)) and b[1] == c[1]:
			print('1')
		else:
			print('2')
	else:
		print('2')


def check(a, b):
	val1 = int(a[0])
	val2 = int(b[0])
	if a == b:
		return 1
	if (val1 + 1 == val2 or val1 + 2 == val2) and a[1] == b[1]:
		return 1
	return 2
ct = 2
l = list(input().split())
l.sort()
val1 = int(l[0][0])
val2 = int(l[1][0])
val3 = int(l[2][0])
if l[0] == l[1] and l[1] == l[2]:
	print(0)
	exit()
elif val1 + 1 == val2 and val2 + 1 == val3 and (l[0][1] == l[1][1] and l[1][1] == l[2][1]):
	print(0)
	exit()
ct = min(ct, check(l[0], l[1]))
ct = min(ct, check(l[1], l[2]))
ct = min(ct, check(l[0], l[2]))
print(ct)


tiles = input().split()
m = []
p = []
s = []
for tile in tiles:
	if tile[-1] == 'm':
		m.append(int(tile[:-1]))
	elif tile[-1] == 'p':
		p.append(int(tile[:-1]))
	elif tile[-1] == 's':
		s.append(int(tile[:-1]))

def get_minimum_extra_tiles(_list):
	if not _list:
		return 3
	_list = sorted(_list)
	max_sequential = 1
	sequential = 1
	max_equal = 1
	equal = 1
	prev = _list[0]
	for item in _list[1:]:
		if item == prev:
			equal += 1
			if equal == 3:
				return 0
		elif item == prev + 1:
			sequential += 1
			if sequential == 3:
				return 0
			if max_equal < equal:
				max_equal = equal
			equal = 1
			prev = item
		elif item == prev + 2:
			if max_sequential < 2:
				max_sequential = 2
			sequential = 1
			if max_equal < equal:
				max_equal = equal
			equal = 1
			prev = item
		else:
			if max_sequential < sequential:
				max_sequential = sequential
			sequential = 1
			if max_equal < equal:
				max_equal = equal
			equal = 1
			prev = item
	if max_sequential < sequential:
		max_sequential = sequential
	if max_equal < equal:
		max_equal = equal
	return max(0, 3 - max(max_equal, max_sequential))
m_min_extra_tiles = get_minimum_extra_tiles(m)
p_min_extra_tiles = get_minimum_extra_tiles(p)
s_min_extra_tiles = get_minimum_extra_tiles(s)
print(min(m_min_extra_tiles, p_min_extra_tiles, s_min_extra_tiles))


cards = input().split(' ')
cards.sort()
cards = [(int(card[0]), card[1]) for card in cards]
if cards[0] == cards[1] and cards[0] == cards[2]:
	koutsuCount = 0
elif cards[0] == cards[1] or cards[1] == cards[2]:
	koutsuCount = 1
else:
	koutsuCount = 2
if cards[0][1] == cards[1][1] and cards[0][1] == cards[2][1]:
	if cards[0][0] + 1 == cards[1][0] and cards[0][0] + 2 == cards[2][0]:
		shuntsuCount = 0
	elif cards[0][0] + 1 == cards[1][0] or cards[0][0] + 2 == cards[1][0] or cards[1][0] + 1 == cards[2][0] or (cards[1][0] + 2 == cards[2][0]):
		shuntsuCount = 1
	else:
		shuntsuCount = 2
elif cards[0][1] == cards[1][1]:
	if cards[0][0] + 1 == cards[1][0] or cards[0][0] + 2 == cards[1][0]:
		shuntsuCount = 1
	else:
		shuntsuCount = 2
elif cards[0][1] == cards[2][1]:
	if cards[0][0] + 1 == cards[2][0] or cards[0][0] + 2 == cards[2][0]:
		shuntsuCount = 1
	else:
		shuntsuCount = 2
elif cards[1][1] == cards[2][1]:
	if cards[1][0] + 1 == cards[2][0] or cards[1][0] + 2 == cards[2][0]:
		shuntsuCount = 1
	else:
		shuntsuCount = 2
else:
	shuntsuCount = 2
print(min(koutsuCount, shuntsuCount))


ms = [i for i in input().split()]
(m1, m2, m3) = [i for i in sorted(ms, reverse=True)]
if m1 == m2 == m3 or (m1[1] == m2[1] == m3[1] and int(m1[0]) == int(m2[0]) + 1 == int(m3[0]) + 2):
	print(0)
elif (m1 == m2 or m2 == m3 or m1 == m3) or (m1[1] == m2[1] and (int(m1[0]) == int(m2[0]) + 1 or int(m1[0]) == int(m2[0]) + 2) or (m1[1] == m3[1] and (int(m1[0]) == int(m3[0]) + 1 or int(m1[0]) == int(m3[0]) + 2)) or (m3[1] == m2[1] and (int(m2[0]) == int(m3[0]) + 1 or int(m2[0]) == int(m3[0]) + 2))):
	print(1)
else:
	print(2)


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()
r = 2
for x in a:
	r = min(r, max(0, 3 - a.count(x)))
	if x[0] < '8':
		r = min(r, (not x.replace(x[0], chr(ord(x[0]) + 1), 1) in a) + (not x.replace(x[0], chr(ord(x[0]) + 2), 1) in a))
	if '1' < x[0] < '9':
		r = min(r, (not x.replace(x[0], chr(ord(x[0]) - 1), 1) in a) + (not x.replace(x[0], chr(ord(x[0]) + 1), 1) in a))
print(r)


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()


from collections import Counter
from itertools import islice

def check_hand():
	hand = list(input().rstrip().split())
	tiles_count = Counter(hand)
	needs = 3 - tiles_count.most_common(1)[0][1]
	if needs == 0:
		print(0)
		return
	by_suit = dict()
	for tile in hand:
		if tile[1] in by_suit:
			by_suit[tile[1]].append(tile[0])
		else:
			by_suit[tile[1]] = [tile[0]]
	for tiles in by_suit:
		by_suit[tiles].sort()
	for tiles in by_suit.values():
		if len(tiles) > 1:
			diffs = [r - l for (l, r) in zip(map(int, tiles), islice(map(int, tiles), 1, None)) if r - l > 0]
			if diffs == [1, 1]:
				print(0)
				return
			elif 2 in diffs or 1 in diffs:
				needs = min(needs, 1)
	print(needs)
check_hand()


def trans(x):
	return int(x[0]) * 10 + {'m': 0, 'p': 1, 's': 2}[x[1]]

def isKoutsu(a, b, c):
	return a == b and a == c

def isShuntsu(a, b, c):
	(x, z) = (max(a, b, c), min(a, b, c))
	y = a + b + c - (x + z)
	return x - y == 10 and y - z == 10
(a, b, c) = map(trans, input().split(' '))
if isKoutsu(a, b, c) or isShuntsu(a, b, c):
	print(0)
	exit(0)
for i in range(1, 10):
	for j in range(0, 3):
		k = i * 10 + j
		if isKoutsu(a, b, k) or isKoutsu(a, c, k) or isKoutsu(c, b, k) or isShuntsu(a, b, k) or isShuntsu(a, c, k) or isShuntsu(c, b, k):
			print(1)
			exit(0)
print(2)


a = list(map(str, input().split()))
p = [0] * 9
m = [0] * 9
s = [0] * 9
p1 = [0] * 9
m1 = [0] * 9
s1 = [0] * 9
p2 = [0] * 9
m2 = [0] * 9
s2 = [0] * 9
for i in a:
	if i[1] == 'p':
		u = int(i[0])
		p[u - 1] += 1
		p2[u - 1] = 1
	elif i[1] == 'm':
		u = int(i[0])
		m[u - 1] += 1
		m2[u - 1] = 1
	else:
		u = int(i[0])
		s[u - 1] += 1
		s2[u - 1] = 1
for i in range(9):
	if i == 0:
		p1[i] = p2[i] + p2[i + 1] + p2[i + 2]
		m1[i] = m2[i] + m2[i + 1] + m2[i + 2]
		s1[i] = s2[i] + s2[i + 1] + s2[i + 2]
	elif i == 8:
		p1[i] = p2[i] + p2[i - 1] + p2[i - 2]
		m1[i] = m2[i] + m2[i - 1] + m2[i - 2]
		s1[i] = s2[i] + s2[i - 1] + s2[i - 2]
	else:
		p1[i] = p2[i] + p2[i + 1] + p2[i - 1]
		m1[i] = m2[i] + m2[i + 1] + m2[i - 1]
		s1[i] = s2[i] + s2[i + 1] + s2[i - 1]
if p.count(3) or m.count(3) or s.count(3) or p1.count(3) or m1.count(3) or (s1.count(3) >= 1):
	print('0')
elif p.count(2) or m.count(2) or s.count(2) or p1.count(2) or m1.count(2) or (s1.count(2) >= 1):
	print('1')
else:
	print('2')


tiles = list(map(str, input().split()))
cnt = [0] * 3
pos = [[0 for x in range(3)] for y in 'mps']
mps = ['m', 'p', 's']
for i in range(3):
	t = tiles[i]
	p = int(mps.index(t[1]))
	cnt[p] += 1
	pos[p][i] = t[0]
if 3 in cnt:
	i = cnt.index(3)
	tmp = pos[i]
	tmp.sort()
	if int(tmp[0]) + 1 == int(tmp[1]) and int(tmp[1]) + 1 == int(tmp[2]):
		print(0)
		exit()
	elif tmp.count(tmp[0]) == len(tmp) and tmp[0] != 0:
		print(0)
		exit()
k = 0
for tmp in pos:
	tmp = list(map(int, tmp))
	tmp.sort()
	if tmp.count(0) > 1:
		continue
	k = tmp.count(tmp[0])
	if int(tmp.count(tmp[1])) > int(k):
		k = tmp.count(tmp[1])
	if k == 2:
		print(1)
		exit()
	if tmp[0] == 0 and int(tmp[2]) - int(tmp[1]) <= 2:
		print(1)
		exit()
	elif int(tmp[2]) - int(tmp[1]) <= 2:
		print(1)
		exit()
	elif int(tmp[1]) - int(tmp[0]) <= 2 and tmp[0] != 0:
		print(1)
		exit()
	else:
		print(2)
		exit()
print(2)


(x, y, z) = sorted((int(n) + 9 * ord(s) for (n, s) in input().split()))
D = {y - x, z - y}
print(2 - bool(D & {0, 1, 2}) - (D < {0, 1}))


a = [x for x in input().split()]
a.sort()
if a[0] == a[1] == a[2]:
	print(0)
elif a[0] == a[1] or a[1] == a[2] or a[0] == a[2]:
	print(1)
elif a[0][1] == a[1][1] == a[2][1] and abs(int(a[0][0]) - int(a[1][0])) == abs(int(a[1][0]) - int(a[2][0])) == 1:
	print(0)
elif (abs(int(a[1][0]) - int(a[0][0])) == 1 or abs(int(a[1][0]) - int(a[0][0])) == 2) and a[1][1] == a[0][1] or ((int(a[2][0]) - int(a[1][0]) == 1 or int(a[2][0]) - int(a[1][0]) == 2) and a[2][1] == a[1][1]) or ((abs(int(a[2][0]) - int(a[0][0])) == 1 or abs(int(a[2][0]) - int(a[0][0])) == 2) and a[2][1] == a[0][1]):
	print(1)
else:
	print(2)


b = list(input().split())
(s, p, m, g) = ([], [], [], [])
for i in range(len(b)):
	if b[i][1] == 's':
		s.append(b[i][0])
	if b[i][1] == 'p':
		p.append(b[i][0])
	if b[i][1] == 'm':
		m.append(b[i][0])
s = list(map(int, s))
m = list(map(int, m))
p = list(map(int, p))
if len(s) == 1:
	g.append(2)
else:
	l = 1
	s.sort()
	for i in range(len(s) - 1):
		if s[i + 1] - s[i] == 1:
			l = l + 1
		elif s[i + 1] - s[i] == 2:
			g.append(3 - l)
			g.append(1)
			l = 1
	g.append(3 - l)
	h = set(s)
	h = list(h)
	for i in range(len(h)):
		k = 0
		for j in range(len(s)):
			if h[i] == s[j]:
				k = k + 1
		g.append(3 - k)
if len(m) == 1:
	g.append(2)
else:
	l = 1
	m.sort()
	for i in range(len(m) - 1):
		if m[i + 1] - m[i] == 1:
			l = l + 1
		elif m[i + 1] - m[i] == 2:
			g.append(3 - l)
			g.append(1)
			l = 1
	g.append(3 - l)
	q = set(m)
	q = list(q)
	for i in range(len(q)):
		k = 0
		for j in range(len(m)):
			if q[i] == m[j]:
				k = k + 1
		g.append(3 - k)
if len(p) == 1:
	g.append(2)
else:
	l = 1
	p.sort()
	for i in range(len(p) - 1):
		if p[i + 1] - p[i] == 1:
			l = l + 1
		elif p[i + 1] - p[i] == 2:
			g.append(3 - l)
			g.append(1)
			l = 1
	g.append(3 - l)
	r = set(p)
	r = list(r)
	for i in range(len(r)):
		k = 0
		for j in range(len(p)):
			if r[i] == p[j]:
				k = k + 1
		g.append(3 - k)
if min(g) < 0:
	print('0')
else:
	print(min(g))


l = input().split()
l = sorted(l)
if l[0] == l[1] == l[2]:
	print(0)
elif l[0][1] == l[1][1] == l[2][1]:
	if int(l[0][0]) + 1 == int(l[1][0]) and int(l[0][0]) + 2 == int(l[2][0]):
		print(0)
	elif int(l[1][0]) - int(l[0][0]) <= 2:
		print(1)
	elif int(l[2][0]) - int(l[0][0]) <= 2:
		print(1)
	elif int(l[2][0]) - int(l[1][0]) <= 2:
		print(1)
	else:
		print(2)
elif l[0][1] == l[1][1]:
	if int(l[1][0]) - int(l[0][0]) <= 2:
		print(1)
	else:
		print(2)
elif l[0][1] == l[2][1]:
	if int(l[2][0]) - int(l[0][0]) <= 2:
		print(1)
	else:
		print(2)
elif l[1][1] == l[2][1]:
	if int(l[2][0]) - int(l[1][0]) <= 2:
		print(1)
	else:
		print(2)
else:
	print(2)


s = input().split()
s.sort()
if s[0] == s[1] == s[2]:
	print(0)
	exit(0)
s[0] = [int(s[0][0]), s[0][1]]
s[1] = [int(s[1][0]), s[1][1]]
s[2] = [int(s[2][0]), s[2][1]]
if s[0][1] == s[1][1] == s[2][1]:
	if s[0][0] + 1 == s[1][0] == s[2][0] - 1:
		print(0)
		exit(0)

def g(x):
	if x[0][1] == x[1][1]:
		if abs(x[1][0] - x[0][0]) < 3:
			return 1
		else:
			return 2
	else:
		return 2
a = min(g([s[0], s[1], s[2]]), g([s[0], s[2], s[1]]), g([s[1], s[0], s[2]]), g([s[1], s[2], s[0]]), g([s[2], s[0], s[1]]), g([s[2], s[1], s[0]]))
print(a)


a = input().split()
d = {}
ds = {}
for i in a:
	if d.get(i[1]):
		d[i[1]].append(int(i[0]))
		d[i[1]].sort()
		ds[i[1]] += 1
	else:
		d[i[1]] = [int(i[0])]
		ds[i[1]] = 1
ds = dict(sorted(ds.items(), key=lambda x: x[1], reverse=True))
for i in ds:
	if ds[i] == 3:
		if len(set(d[i])) == 1:
			print(0)
			break
		elif len(set(d[i])) == 2:
			print(1)
			break
		elif d[i][2] == d[i][1] + 1 and d[i][1] == d[i][0] + 1:
			print(0)
			break
		elif d[i][1] == d[i][0] + 1 or d[i][1] == d[i][0] + 2:
			print(1)
			break
		elif d[i][2] == d[i][1] + 1 or d[i][2] == d[i][1] + 2:
			print(1)
			break
		else:
			print(2)
			break
	elif ds[i] == 2:
		if len(set(d[i])) == 1:
			print(1)
			break
		elif d[i][1] == d[i][0] + 1 or d[i][1] == d[i][0] + 2:
			print(1)
			break
	else:
		print(2)
		break


s = input()
ans = 2
s1 = s[0:2]
s2 = s[3:5]
s3 = s[6:8]

def func(inp):
	ans = 2
	num = int(inp[0])
	c = inp[1]
	ans = min(ans, 2 - int(s.find(str(num + 1) + c) != -1) - int(s.find(str(num + 2) + c) != -1))
	ans = min(ans, 2 - int(s.find(str(num + 1) + c) != -1) - int(s.find(str(num - 1) + c) != -1))
	ans = min(ans, 2 - int(s.find(str(num - 1) + c) != -1) - int(s.find(str(num - 2) + c) != -1))
	ans = min(ans, 3 - s.count(inp))
	return ans
ans = min(ans, func(s1))
ans = min(ans, func(s2))
ans = min(ans, func(s3))
print(ans)


arr = list(map(str, input().split()))
num1 = int(arr[0][0])
num2 = int(arr[1][0])
num3 = int(arr[2][0])
str1 = arr[0][1]
str2 = arr[1][1]
str3 = arr[2][1]
if str1 == str2 and str2 == str3:
	if num1 == num2 and num2 == num3:
		print(0)
	else:
		arr2 = [num1, num2, num3]
		arr2 = sorted(arr2)
		if arr2[0] == arr2[1] - 1 and arr2[1] == arr2[2] - 1:
			print(0)
		elif 0 <= abs(num1 - num2) <= 2:
			print(1)
		elif 0 <= abs(num1 - num3) <= 2:
			print(1)
		elif 0 <= abs(num2 - num3) <= 2:
			print(1)
		else:
			print(2)
elif str1 == str2:
	if abs(num1 - num2) == 0 or abs(num1 - num2) == 1 or abs(num1 - num2) == 2:
		print(1)
	else:
		print(2)
elif str1 == str3:
	if abs(num1 - num3) == 0 or abs(num1 - num3) == 1 or abs(num1 - num3) == 2:
		print(1)
	else:
		print(2)
elif str2 == str3:
	if abs(num2 - num3) == 0 or abs(num2 - num3) == 1 or abs(num2 - num3) == 2:
		print(1)
	else:
		print(2)
else:
	print(2)


n = input()
q = n.replace(' ', '')
a = list(q)
suit = []
no = []
for i in range(6):
	if i % 2 == 0:
		no.append(a[i])
	else:
		suit.append(a[i])
noo = [int(i) for i in no]
temp = [0, 0, 0]
su = 'a'
for i in suit:
	if i == 'm':
		temp[0] += 1
	elif i == 'p':
		temp[1] += 1
	elif i == 's':
		temp[2] += 1
tem = tuple(temp)
mx = 0
ix = 0
for i in range(3):
	if tem[i] > mx:
		mx = tem[i]
		ix = i
if ix == 0:
	su = 'm'
elif ix == 1:
	su = 'p'
else:
	su = 's'
if mx == 1:
	print('2')
else:
	for i in range(3):
		if suit[i] != su:
			noo.pop(i)
	noo.sort()
	if mx == 2:
		wtf = noo[1] - noo[0]
		if wtf <= 2:
			print('1')
		else:
			print('2')
	else:
		c1 = noo[1] - noo[0]
		c2 = noo[2] - noo[1]
		if c1 == 1:
			if c2 == 1:
				print('0')
			else:
				print('1')
		elif c1 == 0:
			if c2 == 0:
				print('0')
			else:
				print('1')
		elif c1 == 2:
			print('1')
		elif c2 <= 2:
			print('1')
		else:
			print('2')


import sys

def solve(t):
	if t[0][1] != t[1][1] and t[0][1] != t[2][1] and (t[1][1] != t[2][1]):
		return 2
	if t[0][1] == t[1][1] and t[1][1] != t[2][1] or (t[0][1] == t[2][1] and t[1][1] != t[0][1]) or (t[1][1] == t[2][1] and t[1][1] != t[0][1]):
		if t[0][1] == t[1][1] and t[1][0] - t[0][0] < 3:
			return 1
		if t[0][1] == t[2][1] and t[2][0] - t[0][0] < 3:
			return 1
		if t[1][1] == t[2][1] and t[2][0] - t[1][0] < 3:
			return 1
		return 2
	if t[0][0] == t[1][0] == t[2][0] or t[0][0] == t[1][0] - 1 == t[2][0] - 2:
		return 0
	if t[1][0] - t[0][0] < 3 or t[2][0] - t[1][0] < 3:
		return 1
	return 2
tiles = [[int(t[0]), t[1]] for t in input().split()]
tiles.sort(key=lambda x: x[0])
print(solve(tiles))


h = sorted(list(input().split()))
if len(set(h)) < 3:
	print(len(set(h)) - 1)
else:
	n = list(map(int, (h[0][0], h[1][0], h[2][0])))
	s = [h[0][1], h[1][1], h[2][1]]
	if len(set(s)) == 3:
		print(2)
	elif len(set(s)) == 2:
		if h[0][1] == h[1][1] and abs(n[0] - n[1]) < 3 or (h[0][1] == h[2][1] and abs(n[0] - n[2]) < 3) or (h[2][1] == h[1][1] and abs(n[2] - n[1]) < 3):
			print(1)
		else:
			print(2)
	elif max(n) - min(n) == 2:
		print(0)
	elif abs(n[0] - n[1]) < 3 or abs(n[0] - n[2]) < 3 or abs(n[2] - n[1]) < 3:
		print(1)
	else:
		print(2)


def letter(i):
	return (i[1], i[0])
arr = [i for i in filter(None, input().split(' '))]
a = sorted(arr, key=letter)
min = 2
t = len(a)
num = int(a[0][0])
letter = a[0][1]
if a[0] == a[1]:
	min = 1
	if a[1] == a[2]:
		min = 0
if int(a[0][0]) + 1 == int(a[1][0]) and a[1][1] == letter:
	if min > 0:
		min = 1
	if int(a[2][0]) == num + 2 and a[2][1] == letter:
		min = 0
if int(a[0][0]) + 2 == int(a[1][0]) and a[1][1] == letter:
	if min > 0:
		min = 1
letter = a[1][1]
num = int(a[1][0])
if a[1] == a[2]:
	if min > 0:
		min = 1
if int(a[1][0]) + 1 == int(a[2][0]) and a[2][1] == letter:
	if min > 0:
		min = 1
if int(a[1][0]) + 2 == int(a[2][0]) and a[2][1] == letter:
	if min > 0:
		min = 1
print(min)


tiles = [tile for tile in input().split()]
tiles = sorted(tiles)
num0 = int(tiles[0][0])
suit0 = tiles[0][1]
num1 = int(tiles[1][0])
suit1 = tiles[1][1]
num2 = int(tiles[2][0])
suit2 = tiles[2][1]
if suit0 == suit1 == suit2:
	if num0 == num1 == num2 or (abs(num0 - num1) == 1 and abs(num1 - num2) == 1 and (abs(num0 - num2) == 2)):
		print(0)
	elif abs(num0 - num1) > 2 and abs(num1 - num2) > 2 and (abs(num0 - num2) > 2):
		print(2)
	else:
		print(1)
elif suit1 == suit2:
	if num1 == num2:
		print(1)
	elif abs(num1 - num2) > 2:
		print(2)
	else:
		print(1)
elif suit1 == suit0:
	if num1 == num0:
		print(1)
	elif abs(num1 - num0) > 2:
		print(2)
	else:
		print(1)
elif suit2 == suit0:
	if num0 == num2:
		print(1)
	elif abs(num0 - num2) > 2:
		print(2)
	else:
		print(1)
else:
	print(2)


a = list(input().split())
p = []
m = []
s = []
for i in a:
	if i[1] == 'p':
		p.append(int(i[0]))
	if i[1] == 'm':
		m.append(int(i[0]))
	if i[1] == 's':
		s.append(int(i[0]))
ans = 2
p.sort()
m.sort()
s.sort()
if len(p) == 2 and p[1] - p[0] < 3:
	ans = 1
if len(m) == 2 and m[1] - m[0] < 3:
	ans = 1
if len(s) == 2 and s[1] - s[0] < 3:
	ans = 1
if len(p) == 3 and (p[1] - p[0] < 3 or p[2] - p[1] < 3):
	ans = 1
if len(m) == 3 and (m[1] - m[0] < 3 or m[2] - m[1] < 3):
	ans = 1
if len(s) == 3 and (s[1] - s[0] < 3 or s[2] - s[1] < 3):
	ans = 1
if len(p) == 3 and p[0] == p[1] and (p[0] == p[2]):
	ans = 0
if len(m) == 3 and m[0] == m[1] and (m[0] == m[2]):
	ans = 0
if len(s) == 3 and s[0] == s[1] and (s[0] == s[2]):
	ans = 0
if len(p) == 3 and p[1] - p[0] == 1 and (p[2] - p[1] == 1):
	ans = 0
if len(m) == 3 and m[1] - m[0] == 1 and (m[2] - m[1] == 1):
	ans = 0
if len(s) == 3 and s[1] - s[0] == 1 and (s[2] - s[1] == 1):
	ans = 0
print(ans)


t = input().split(sep=' ')
t.sort(key=lambda i: i[0])
n = list(map(lambda i: int(i[0]), t))
b = list(map(lambda i: i[1], t))
if t[0] == t[1] and t[1] == t[2]:
	print(0)
elif n[0] + 1 == n[1] and n[1] + 1 == n[2] and (b[0] == b[1]) and (b[1] == b[2]):
	print(0)
elif b[0] == b[1] and n[0] == n[1] or (b[1] == b[2] and n[1] == n[2]) or (b[0] == b[2] and n[2] == n[0]) or (b[0] == b[2] and (n[0] + 1 == n[2] or n[0] + 2 == n[2])) or (b[1] == b[2] and (n[1] + 1 == n[2] or n[1] + 2 == n[2])) or (b[1] == b[0] and (n[0] + 1 == n[1] or n[0] + 2 == n[1])):
	print(1)
else:
	print(2)


input_ = input()
input_ = input_.split(' ')
arg1 = input_[0]
arg2 = input_[1]
arg3 = input_[2]

def calc(arg1, arg2, arg3):
	if arg1 == arg2:
		if arg1 == arg3:
			return 0
		return 1
	if arg1 == arg3:
		return 1
	if arg2 == arg3:
		return 1
	if arg1[1] == arg2[1]:
		if arg1[1] == arg3[1]:
			numb = list()
			numb.append(int(arg1[0]))
			numb.append(int(arg2[0]))
			numb.append(int(arg3[0]))
			numb.sort()
			if numb[1] - numb[0] == 1:
				if numb[2] - numb[1] == 1:
					return 0
				return 1
			if numb[2] - numb[1] == 1:
				return 1
			if numb[1] - numb[0] == 2 or numb[2] - numb[1] == 1:
				return 1
			return 2
		if int(arg1[0]) - int(arg2[0]) < 3 and int(arg1[0]) - int(arg2[0]) > -3:
			return 1
	if arg1[1] == arg3[1]:
		if int(arg1[0]) - int(arg3[0]) < 3 and int(arg1[0]) - int(arg3[0]) > -3:
			return 1
	if arg2[1] == arg3[1]:
		if int(arg3[0]) - int(arg2[0]) < 3 and int(arg3[0]) - int(arg2[0]) > -3:
			return 1
	return 2
res = calc(arg1, arg2, arg3)
if res is None:
	print(2)
else:
	print(res)


from sys import stdin
from math import fabs
x = [i for i in stdin.readline().split()]
x.sort()
if x[0] == x[2]:
	print(0)
elif int(x[0][0]) + 2 == int(x[1][0]) + 1 == int(x[2][0]) and x[0][1] == x[1][1] == x[2][1]:
	print(0)
elif x[0][1] == x[1][1] and int(x[1][0]) - int(x[0][0]) <= 2:
	print(1)
elif x[0][1] == x[2][1] and int(x[2][0]) - int(x[0][0]) <= 2:
	print(1)
elif x[2][1] == x[1][1] and int(x[2][0]) - int(x[1][0]) <= 2:
	print(1)
else:
	print(2)


st = input().split()
m = []
p = []
s = []
for i in range(len(st)):
	if st[i][1] == 's':
		s.append(int(st[i][0]))
	elif st[i][1] == 'm':
		m.append(int(st[i][0]))
	else:
		p.append(int(st[i][0]))
lst = [m, p, s]
a = m
for i in range(1, len(lst)):
	if len(lst[i]) > len(a):
		a = lst[i]
a.sort()
like = 2
shoes = 2
if len(a) == 1:
	print(2)
elif len(a) == 2:
	if abs(a[1] - a[0]) == 1 or abs(a[1] - a[0]) == 2 or a[1] - a[0] == 0:
		print(1)
	else:
		print(2)
else:
	if abs(a[1] - a[2]) == 1 or abs(a[0] - a[1]) == 1 or abs(a[2] - a[0]) == 1:
		like -= 1
	elif abs(a[1] - a[2]) == 2 or abs(a[0] - a[1]) == 2 or abs(a[2] - a[0]) == 2:
		like -= 1
	if abs(a[1] - a[2]) == 1 and abs(a[2] - a[0]) == 2:
		like -= 1
	if a[1] == a[0] or a[1] == a[2] or a[0] == a[2]:
		shoes -= 1
	if a[1] == a[0] == a[2]:
		shoes -= 1
	print(min(like, shoes))


strInput = input()
m = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
s = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
p = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
nekoHands = 0
while nekoHands + 1 <= len(strInput):
	if strInput[nekoHands] == ' ':
		nekoHands += 1
	elif '9' >= strInput[nekoHands] >= '1':
		if strInput[nekoHands + 1] == 'm':
			m[int(strInput[nekoHands])] += 1
		elif strInput[nekoHands + 1] == 's':
			s[int(strInput[nekoHands])] += 1
		elif strInput[nekoHands + 1] == 'p':
			p[int(strInput[nekoHands])] += 1
		nekoHands += 2
	else:
		print('error!')
maxKoutsu = 0
if 3 in m + s + p:
	maxKoutsu = 3
elif 2 in m + s + p:
	maxKoutsu = 2
elif 1 in m + s + p:
	maxKoutsu = 1
nekoFeet = 0
maxShuntsu = 1
while nekoFeet + 1 <= 9:
	if m[nekoFeet] > 0 and m[nekoFeet + 1] > 0 and (m[nekoFeet + 2] > 0) and (maxShuntsu < 3):
		maxShuntsu = 3
		break
	elif m[nekoFeet] > 0 and (m[nekoFeet + 1] > 0 or m[nekoFeet + 2] > 0) and (maxShuntsu < 2):
		maxShuntsu = 2
	if s[nekoFeet] > 0 and s[nekoFeet + 1] > 0 and (s[nekoFeet + 2] > 0) and (maxShuntsu < 3):
		maxShuntsu = 3
		break
	elif s[nekoFeet] > 0 and (s[nekoFeet + 1] > 0 or s[nekoFeet + 2] > 0) and (maxShuntsu < 2):
		maxShuntsu = 2
	if p[nekoFeet] > 0 and p[nekoFeet + 1] > 0 and (p[nekoFeet + 2] > 0) and (maxShuntsu < 3):
		maxShuntsu = 3
		break
	elif p[nekoFeet] > 0 and (p[nekoFeet + 1] > 0 or p[nekoFeet + 2] > 0) and (maxShuntsu < 2):
		maxShuntsu = 2
	nekoFeet += 1
if maxKoutsu > maxShuntsu:
	print(3 - maxKoutsu)
else:
	print(3 - maxShuntsu)


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
	if res == 2:
		for c in lis:
			x = int(c[0]) + 2
			ch = str(x) + c[1]
			if ch in s:
				res -= 1
		if res == 0:
			res = 1
	print(res)


f = lambda c: 'mps'.index(c)
l = [[], [], []]
for c in input().split():
	(a, b) = c
	l[f(b)].append(int(a))
for i in range(3):
	l[i].sort()
res = 3
for x in l:
	if len(x) == 0:
		continue
	elif len(x) == 1:
		res = min(res, 2)
	elif len(x) == 3:
		if len(set(x)) == 1:
			res = min(res, 0)
			break
		if x[0] == x[1] - 1 and x[1] == x[2] - 1:
			res = min(res, 0)
			break
	res = min(res, 2)
	for i in range(len(x)):
		for j in range(i + 1, len(x)):
			if abs(x[i] - x[j]) <= 2:
				res = min(res, 1)
print(res)


a = sorted(list(map(lambda x: ord(x[0]) + 256 * ord(x[1]), input().split())))
res = 2
if a[1] - a[0] in [0, 1, 2] or a[2] - a[1] in [0, 1, 2]:
	res = 1
if a[0] == a[1] and a[1] == a[2] or (a[0] + 1 == a[1] and a[1] + 1 == a[2]):
	res = 0
print(res)


def split(s):
	return [int(s[0]), s[1]]

def check_seq(nums, colors):
	for n in nums:
		if n not in range(1, 10):
			return False
	if len(set(colors)) != 1:
		return False
	nums = set(sorted(nums))
	a = sorted(nums)[0]
	return {a, a + 1, a + 2} == nums

def main():
	(a, b, c) = input().split(' ')
	if len(set([a, b, c])) == 1:
		return 0
	(a1, a2) = split(a)
	(b1, b2) = split(b)
	(c1, c2) = split(c)
	domcol = None
	if check_seq([a1, b1, c1], [a2, b2, c2]):
		return 0
	if len(set([a, b, c])) == 2:
		return 1
	if len(set([a2, b2, c2])) <= 2:
		domcol = a2
		if a2 != b2:
			if a2 != c2:
				domcol = c2
		ns = set([])
		if a2 == domcol:
			ns = ns | {a1}
		if b2 == domcol:
			ns = ns | {b1}
		if c2 == domcol:
			ns = ns | {c1}
		for n in ns:
			if len(set([a2, b2, c2])) == 2:
				if check_seq(list(ns) + [n - 1], [domcol] * 3):
					return 1
				if check_seq(list(ns) + [n + 1], [domcol] * 3):
					return 1
			else:
				for d in {-1, 1}:
					nns = set(ns) | {n + d}
					for x in nns:
						ms = nns.difference({x})
						if check_seq(list(ms), [domcol] * 3):
							return 1
						if check_seq(list(ms), [domcol] * 3):
							return 1
	return 2
print(main())


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')
	elif number[2] - number[0] > 2:
		print('2')
	else:
		print('1')
else:
	print('2')


from collections import defaultdict
sa = input().split()
groups = defaultdict(list)
for el in sa:
	groups[el[-1]].append(int(el[0]))
test_arrays = []
for i in range(1, 8):
	test_arrays.append([i, i + 1, i + 2])
min_card = 2
for elements in groups.values():
	els = sorted(elements)
	for i in range(1, 10):
		count = els.count(i)
		if count == 3:
			print(0)
			exit()
		if count == 2:
			print(1)
			exit()
	for ta in test_arrays:
		m = 3
		for i in ta:
			if i in els:
				m -= 1
		if m < min_card:
			min_card = m
			if m == 0:
				print(0)
				exit()
print(min_card)


a = list(map(str, input().split()))
a.sort()
if a[0] == a[1] == a[2]:
	print(0)
elif a[0][1] == a[1][1] == a[2][1] and int(a[0][0]) == int(a[1][0]) - 1 and (int(a[1][0]) == int(a[2][0]) - 1):
	print(0)
elif a[0] == a[1] or a[1] == a[2] or a[0] == a[2]:
	print(1)
elif a[0][1] == a[1][1] and abs(int(a[0][0]) - int(a[1][0])) <= 2:
	print(1)
elif a[1][1] == a[2][1] and abs(int(a[1][0]) - int(a[2][0])) <= 2:
	print(1)
elif a[0][1] == a[2][1] and abs(int(a[0][0]) - int(a[2][0])) <= 2:
	print(1)
else:
	print(2)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
ml = inp().split()
ans = len(set(ml)) - 1
for i in range(1, 10):
	for j in 'psm':
		k = 3
		if str(i) + j in ml:
			k -= 1
		if str(i + 1) + j in ml:
			k -= 1
		if str(i + 2) + j in ml:
			k -= 1
		ans = min(ans, k)
print(ans)


(a, b, c) = sorted(input().split())
v = 2
if a == b == c:
	v = 0
elif a == b or a == c or b == c:
	v = 1
else:
	(x, y, z) = (int(a[0]), int(b[0]), int(c[0]))
	if a[1] == b[1] == c[1] and x + 1 == y and (y + 1 == z):
		v = 0
	elif a[1] == b[1] and 0 < y - x < 3 or (a[1] == c[1] and 0 < z - x < 3) or (b[1] == c[1] and 0 < z - y < 3):
		v = 1
print(v)


(t1, t2, t3) = input().split()
if t1 == t2 == t3:
	print(0)
else:
	s = []
	m = []
	p = []
	for elem in (t1, t2, t3):
		if elem[1] == 's':
			s.append(int(elem[0]))
		elif elem[1] == 'm':
			m.append(int(elem[0]))
		else:
			p.append(int(elem[0]))
	x = max(len(s), len(m), len(p))
	if len(s) == x:
		mentsu = s
	elif len(m) == x:
		mentsu = m
	else:
		mentsu = p
	mentsu.sort()
	if len(mentsu) == 3 and mentsu[0] + 2 == mentsu[1] + 1 == mentsu[2]:
		print(0)
	else:
		kc = [0 for i in range(11)]
		for elem in mentsu:
			elem = elem + 1
			kc[elem] += 1
			if kc[elem - 1] > 0 or kc[elem - 2] > 0 or kc[elem] >= 2:
				print(1)
				break
		else:
			print(2)


from sys import exit
t = input().split()[:3]
s = set(t)
res = 3
if len(s) == 1:
	res = min(res, 0)
elif len(s) == 2:
	res = min(res, 1)
elif len(s) == 3:
	res = min(res, 2)
if res == 0:
	print(res)
	exit(0)
t.sort()
m = [int(a[0]) for a in t if a[1] == 'm']
p = [int(a[0]) for a in t if a[1] == 'p']
s = [int(a[0]) for a in t if a[1] == 's']

def f(a):
	res = 2
	for i in a:
		if i - 1 in a and i + 1 in a or (i - 2 in a and i - 1 in a) or (i + 1 in a and i + 2 in a):
			return 0
		elif i - 1 in a or i + 1 in a or i - 2 in a or (i + 2 in a):
			res = min(res, 1)
	return res
res = min([res, f(m), f(p), f(s)])
print(res)


a = input().split()
a.sort()
flag1 = 3
if a[0] == a[1] and a[1] == a[2]:
	flag1 = 0
elif a[0] == a[1]:
	flag1 = 1
elif a[1] == a[2]:
	flag1 = 1
else:
	flag1 = 2
flag2 = 3
if a[0][1] == a[1][1] and a[1][1] == a[2][1]:
	if int(a[1][0]) - int(a[0][0]) == 1 and int(a[2][0]) - int(a[1][0]) == 1:
		flag2 = 0
	elif int(a[1][0]) - int(a[0][0]) == 1 or int(a[1][0]) - int(a[0][0]) == 2:
		flag2 = 1
	elif int(a[2][0]) - int(a[1][0]) == 1 or int(a[2][0]) - int(a[1][0]) == 2:
		flag2 = 1
	else:
		flag2 = 2
elif a[0][1] == a[1][1]:
	if int(a[1][0]) - int(a[0][0]) == 1 or int(a[1][0]) - int(a[0][0]) == 2:
		flag2 = 1
	else:
		flag2 = 2
elif a[1][1] == a[2][1]:
	if int(a[2][0]) - int(a[1][0]) == 1 or int(a[2][0]) - int(a[1][0]) == 2:
		flag2 = 1
	else:
		flag2 = 2
elif a[0][1] == a[2][1]:
	if int(a[2][0]) - int(a[0][0]) == 1 or int(a[2][0]) - int(a[0][0]) == 2:
		flag2 = 1
	else:
		flag2 = 2
else:
	flag2 = 2
print(min(flag1, flag2))


a = [i for i in input().split()]
m_dict = {'m': [], 'p': [], 's': []}
for word in a:
	m_dict[word[1]].append(int(word[0]))
val = 2
for i in ['m', 'p', 's']:
	temp = m_dict[i]
	if len(temp) == 2:
		if temp[0] == temp[1] or abs(temp[0] - temp[1]) <= 2:
			val = 1
			break
	if len(temp) == 3:
		temp = sorted(temp)
		if temp[0] == temp[1] and temp[1] == temp[2]:
			val = 0
			break
		elif temp[1] == temp[0] + 1 and temp[2] == temp[1] + 1:
			val = 0
			break
		elif temp[1] == temp[0] or temp[1] == temp[2]:
			val = 1
			break
		elif temp[1] - temp[0] <= 2 or temp[2] - temp[1] <= 2:
			val = 1
			break
print(val)


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)


def parse_string_to_counts(input):
	color_digit = {}
	for x in input:
		(digit, color) = (int(x[0]), x[1])
		if color not in color_digit:
			color_digit[color] = {}
		if digit not in color_digit[color]:
			color_digit[color][digit] = 0
		color_digit[color][digit] += 1
	return color_digit

def smallest_needed(input):
	color_digit = parse_string_to_counts(input)
	min_number = 3
	for values in color_digit.values():
		min_same = get_min_same(values)
		min_consercutive = get_min_consercutive(values)
		min_number = min(min_number, min_same, min_consercutive)
	return min_number

def get_min_same(digit_counts):
	return max(0, 3 - max(digit_counts.values()))

def get_min_consercutive(digit_counts):
	min_count = 3
	for key in digit_counts:
		if key + 1 in digit_counts and key + 2 in digit_counts:
			return 0
		elif key + 1 in digit_counts or key + 2 in digit_counts:
			min_count = min(min_count, 1)
		else:
			min_count = min(min_count, 2)
	return min_count
input = input().split()
print(smallest_needed(input))


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, Counter
import math
import heapq

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

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
tiles = stringListIn()
(ch1, ch2, ch3) = (tiles[0][1], tiles[1][1], tiles[2][1])
if ch1 == ch2 and ch2 == ch3:
	tiles = sorted(tiles)
else:
	tiles = sorted(tiles, key=lambda x: x[1])
c = Counter(tiles)
m = max(c.values())
if m >= 2:
	print(3 - m)
else:
	num = int(tiles[0][0])
	ch = tiles[0][1]
	count = 1
	flag = 1
	for tile in tiles[1:]:
		if ch == tile[1]:
			if abs(int(tile[0]) - num) <= 2:
				count += 1
			else:
				ch = tile[1]
				num = int(tile[0])
		else:
			ch = tile[1]
			num = int(tile[0])
	print(3 - count)


m = {'s': [0] * 9, 'm': [0] * 9, 'p': [0] * 9}
for e in input().split():
	m[e[1]][int(e[0]) - 1] += 1
ret = 2
for t in 'smp':
	l = m[t]
	if max(l) >= 2:
		ret = min(ret, 3 - max(l))
	else:
		for i in range(7):
			seq = sum(l[i:i + 3])
			ret = min(ret, 3 - seq)
print(ret)


a = input()
k = 0
a1 = a[0] + a[1]
a2 = a[3] + a[4]
a3 = a[6] + a[7]
q = []
w = []
w1 = []
q1 = []
t = []
t1 = [0] * 3
w.append(int(a[0]))
w.append(int(a[3]))
w.append(int(a[6]))
q.append(a[1])
q.append(a[4])
q.append(a[7])
t = sorted(w)
t = list(t)
for i in range(3):
	m = w.index(t[i])
	del w[w.index(t[i])]
	t1[i] = q[m]
	del q[m]
if a1 == a2 and a2 == a3 and (a1 == a3):
	print(0)
elif a1 == a2 or a2 == a3 or a1 == a3:
	print(1)
elif t1[0] == t1[1] == t1[2] and t[0] + 1 == t[1] == t[2] - 1:
	print(0)
elif t1[0] == t1[1] and (abs(t[1] - t[0]) == 1 or abs(t[1] - t[0]) == 2) or (t1[0] == t1[2] and (abs(t[2] - t[0]) == 1 or abs(t[2] - t[0]) == 2)) or (t1[2] == t1[1] and (abs(t[1] - t[2]) == 1 or abs(t[1] - t[2]) == 2)):
	print(1)
else:
	print(2)


line = input().split()
line.sort()
(a, b, c) = line
if a == b and a == c:
	print(0)
elif a == b:
	print(1)
elif b == c:
	print(1)
elif a[1] == b[1] and b[1] == c[1] and (int(b[0]) - int(a[0]) == 1) and (int(c[0]) - int(b[0]) == 1):
	print(0)
elif a[1] == b[1] and int(b[0]) - int(a[0]) in [1, 2]:
	print(1)
elif b[1] == c[1] and int(c[0]) - int(b[0]) in [1, 2]:
	print(1)
elif a[1] == c[1] and int(c[0]) - int(a[0]) in [1, 2]:
	print(1)
else:
	print(2)


a = [x for x in input().split()]
m = []
p = []
s = []
for x in a:
	if x[1] == 'm':
		m.append(int(x[0]))
	elif x[1] == 'p':
		p.append(int(x[0]))
	else:
		s.append(int(x[0]))
maxi = max(len(m), len(p), len(s))
new = [m, p, s]
if maxi == 1:
	print('2')
elif maxi == 2:
	for x in new:
		if len(x) == maxi:
			x.sort()
			if x[0] == x[1] or x[0] + 1 == x[1] or x[0] + 2 == x[1]:
				print('1')
			else:
				print('2')
			break
else:
	for x in new:
		if len(x) == maxi:
			x.sort()
			if x[0] == x[1] == x[2] or (x[0] + 1 == x[1] and x[1] + 1 == x[2]):
				print('0')
			elif x[0] == x[1] or x[1] == x[2]:
				print('1')
			elif x[0] + 1 == x[1] or x[1] + 1 == x[2]:
				print('1')
			elif x[0] + 2 == x[1] or x[0] + 2 == x[2] or x[1] + 2 == x[2]:
				print('1')
			else:
				print('2')
			break


(a, b, c) = input().split()
t = sorted([(int(a[0]), a[1]), (int(b[0]), b[1]), (int(c[0]), c[1])])
if t[0] == t[1] and t[1] == t[2]:
	print(0)
	exit(0)
if t[0][1] == t[1][1] and t[1][1] == t[2][1] and (t[0][0] + 1 == t[1][0]) and (t[1][0] + 1 == t[2][0]):
	print(0)
	exit(0)
if t[0] == t[1]:
	print(1)
	exit(0)
if t[1] == t[2]:
	print(1)
	exit(0)
if t[0] == t[2]:
	print(1)
	exit(0)
if t[0][1] == t[1][1] and t[0][0] + 1 == t[1][0]:
	print(1)
	exit(0)
if t[1][1] == t[2][1] and t[1][0] + 1 == t[2][0]:
	print(1)
	exit(0)
if t[0][1] == t[2][1] and t[0][0] + 1 == t[2][0]:
	print(1)
	exit(0)
if t[0][1] == t[1][1] and t[0][0] + 2 == t[1][0]:
	print(1)
	exit(0)
if t[1][1] == t[2][1] and t[1][0] + 2 == t[2][0]:
	print(1)
	exit(0)
if t[0][1] == t[2][1] and t[0][0] + 2 == t[2][0]:
	print(1)
	exit(0)
print(2)


from collections import Counter
cards = input().split()
suits = ['m', 'p', 's']

def hasKoutsu(cards):
	return max([y for (x, y) in Counter(cards).items()]) >= 3

def hasShuntsu(cards):
	cnt = Counter(cards)
	for suit in suits:
		for i in range(3, 10):
			a = [str(j) + suit for j in range(i - 2, i + 1)]
			if sum([1 if cnt.get(x, 0) > 0 else 0 for x in a]) >= 3:
				return True
	return False

def hasMentsu(cards):
	return hasKoutsu(cards) or hasShuntsu(cards)
allCards = [None]
for i in range(1, 10):
	for suit in suits:
		allCards.append(str(i) + suit)
result = 3
for x in allCards:
	for y in allCards:
		newCards = list(cards)
		if x:
			newCards.append(x)
		if y:
			newCards.append(y)
		if hasMentsu(newCards):
			result = min(result, len(newCards) - 3)
print(result)


import sys
import math
import bisect
from collections import deque
sys.setrecursionlimit(1000000000)

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

def iinput():
	return int(input())

def finput():
	return float(input())

def tinput():
	return input().split()

def rinput():
	return map(str, tinput())

def rlinput():
	return list(rinput())

def modst(a, s):
	res = 1
	while s:
		if s % 2:
			res *= a
		a *= a
		s //= 2
	return res

def main():
	s = rlinput()
	res = 10 ** 18
	for i in map(str, range(1, 10)):
		for p in ('m', 'p', 's'):
			k = s.count(i + p)
			res = min(res, 3 - k)
	for i in range(1, 8):
		for p in ('m', 'p', 's'):
			k = 0
			if str(i) + p in s:
				k += 1
			if str(i + 1) + p in s:
				k += 1
			if str(i + 2) + p in s:
				k += 1
			res = min(res, 3 - k)
	print(res)
for i in range(1):
	main()


(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
z = 0
for i in d:
	z = max(z, max(i))
if z == 3:
	min_m = min(0, min_m)
elif z == 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)
			elif d[j][i - 1] == d[j][i + 1] == 1:
				min_m = min(1, min_m)
min_m = min(2, min_m)
print(min_m)


l = input().split()
s = []
m = []
p = []
for i in range(3):
	if l[i][1] == 's':
		s.append(l[i][0])
	if l[i][1] == 'm':
		m.append(l[i][0])
	if l[i][1] == 'p':
		p.append(l[i][0])
r = 2
for s in [s, m, p]:
	s = list(map(int, s))
	s.sort()
	if len(s) > 1:
		for i in range(10):
			if i in s and i + 1 in s and (i + 2 in s):
				r = min(r, 0)
			if i in s and s.count(i) == 3:
				r = min(r, 0)
		for j in range(1, 10):
			s_ = s.copy()
			s_.append(j)
			for i in range(10):
				if i in s_ and i + 1 in s_ and (i + 2 in s_):
					r = min(r, 1)
				if i in s_ and s_.count(i) == 3:
					r = min(r, 1)
print(r)


ans = 2
x = input().split()
for i in ['m', 's', 'p']:
	c = [int(j[0]) for j in x if j[1] == i]
	c.sort()
	if len(c) < 2:
		continue
	if len(c) == 3:
		if c[0] == c[1] and c[1] == c[2]:
			ans = 0
			break
		if c[0] + 1 == c[1] and c[1] + 1 == c[2]:
			ans = 0
			break
		if c[0] == c[1] or c[0] + 1 == c[1] or c[0] + 2 == c[1]:
			ans = 1
			continue
		if c[1] == c[2] or c[1] + 1 == c[2] or c[1] + 2 == c[2]:
			ans = 1
			continue
	if c[0] == c[1] or c[0] + 1 == c[1] or c[0] + 2 == c[1]:
		ans = 1
print(ans)


(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)


(s1, s2, s3) = input().split()
A = []
if s1[1] == s2[1] and s2[1] == s3[1]:
	if s1[0] == s2[0] and s2[0] == s3[0]:
		print(0)
		exit()
	A.append(int(s1[0]))
	A.append(int(s2[0]))
	A.append(int(s3[0]))
	A.sort()
	if A[0] == A[1] - 1 and A[0] == A[2] - 2:
		print(0)
		exit()
if s1[1] == s2[1]:
	if s1[0] == s2[0]:
		print(1)
		exit()
	if int(s1[0]) == int(s2[0]) + 1 or int(s1[0]) == int(s2[0]) - 1:
		print(1)
		exit()
	if int(s1[0]) == int(s2[0]) + 2 or int(s1[0]) == int(s2[0]) - 2:
		print(1)
		exit()
if s1[1] == s3[1]:
	if s1[0] == s3[0]:
		print(1)
		exit()
	if int(s1[0]) == int(s3[0]) + 1 or int(s1[0]) == int(s3[0]) - 1:
		print(1)
		exit()
	if int(s1[0]) == int(s3[0]) + 2 or int(s1[0]) == int(s3[0]) - 2:
		print(1)
		exit()
if s2[1] == s3[1]:
	if s2[0] == s3[0]:
		print(1)
		exit()
	if int(s2[0]) == int(s3[0]) + 1 or int(s2[0]) == int(s3[0]) - 1:
		print(1)
		exit()
	if int(s2[0]) == int(s3[0]) + 2 or int(s2[0]) == int(s3[0]) - 2:
		print(1)
		exit()
print(2)


l = [0] * 150
(a, b, c) = input().split()
l[ord(a[1])] += 1
l[ord(b[1])] += 1
l[ord(c[1])] += 1
var = {}
var[1] = 0
for i in range(120):
	if i == 115:
		if var[1] < l[i]:
			var[1] = l[i]
			var[2] = 's'
	if i == 112:
		if var[1] < l[i]:
			var[1] = l[i]
			var[2] = 'p'
	if i == 109:
		if var[1] < l[i]:
			var[1] = l[i]
			var[2] = 'm'
cha = 0
chb = 0
n = []
m = []
if var[1] == 1:
	print(2)
elif var[1] == 2:
	if a[1] == var[2]:
		cha += 1
	if b[1] == var[2]:
		chb += 1
		if cha == 1:
			if abs(int(a[0]) - int(b[0])) == 0 or abs(int(a[0]) - int(b[0])) == 1 or abs(int(a[0]) - int(b[0])) == 2:
				print(1)
			else:
				print(2)
	if c[1] == var[2]:
		if cha == 1:
			if abs(int(a[0]) - int(c[0])) == 0 or abs(int(a[0]) - int(c[0])) == 1 or abs(int(a[0]) - int(c[0])) == 2:
				print(1)
			else:
				print(2)
		elif abs(int(c[0]) - int(b[0])) == 0 or abs(int(c[0]) - int(b[0])) == 1 or abs(int(c[0]) - int(b[0])) == 2:
			print(1)
		else:
			print(2)
else:
	n.append(int(a[0]))
	n.append(int(b[0]))
	n.append(int(c[0]))
	m.append(int(a[0]))
	m.append(int(b[0]))
	m.append(int(c[0]))
	n.sort()
	m.sort()
	n = list(set(n))
	if len(n) == 1:
		print(0)
	elif len(n) == 2:
		print(1)
	elif n[1] - n[0] == 1 and n[2] - n[1] == 1:
		print(0)
	elif n[1] - n[0] == 1 or n[1] - n[0] == 2 or n[2] - n[1] == 1 or (n[2] - n[1] == 2):
		print(1)
	else:
		print(2)


tt = input().split()
tt = sorted(tt)

def koutsu():
	one_and_two_equal = tt[0] == tt[1]
	two_and_three_equal = tt[1] == tt[2]
	one_and_three_equal = tt[0] == tt[2]
	all_equal = one_and_two_equal and two_and_three_equal
	two_equal = one_and_two_equal or two_and_three_equal or one_and_three_equal
	if all_equal:
		return 0
	if two_equal:
		return 1
	return 2

def part_shuntsu(a, b):
	return int(tt[b][0]) - int(tt[a][0]) == 1 and tt[b][1] == tt[a][1]

def possible_shuntsu(a, b):
	return int(tt[b][0]) - int(tt[a][0]) == 2 and tt[b][1] == tt[a][1]

def shuntsu():
	one_and_two_seq = part_shuntsu(0, 1)
	two_and_three_seq = part_shuntsu(1, 2)
	one_and_three_seq = part_shuntsu(0, 2)
	one_and_two_possible_seq = possible_shuntsu(0, 1)
	one_and_three_possible_seq = possible_shuntsu(0, 2)
	two_and_three_possible_seq = possible_shuntsu(1, 2)
	full_seq = one_and_two_seq and two_and_three_seq
	possible_seq = one_and_two_possible_seq or one_and_three_possible_seq or two_and_three_possible_seq
	part_seq = one_and_two_seq or two_and_three_seq or one_and_three_seq or possible_seq
	if full_seq:
		return 0
	if part_seq:
		return 1
	return 2
print(min(shuntsu(), koutsu()))


(s1, s2, s3) = input().split()
f = [(int(s1[0]), s1[1]), (int(s2[0]), s2[1]), (int(s3[0]), s3[1])]
f = sorted(f, key=lambda tup: tup[0])
m = 2
if s1 == s2 and s2 == s3:
	m = 0
elif f[0][0] == f[1][0] - 1 and f[1][0] == f[2][0] - 1 and (s1[1] == s2[1]) and (s2[1] == s3[1]):
	m = 0
elif f[0][1] == f[1][1] and f[0][0] == f[1][0] - 1 or (f[0][1] == f[2][1] and f[0][0] == f[2][0] - 1) or (f[0][1] == f[1][1] and f[0][0] == f[1][0] - 2) or (f[1][1] == f[2][1] and f[1][0] == f[2][0] - 2) or (f[0][1] == f[2][1] and f[0][0] == f[2][0] - 2) or (f[1][1] == f[2][1] and f[1][0] == f[2][0] - 1) or (s1 == s2) or (s2 == s3) or (s1 == s3):
	m = 1
print(m)


a = input().split()
b = []
x = {'s': 0, 'm': 0, 'p': 0}
for i in range(0, 3):
	b.append(int(a[i][0]))
	x[a[i][1]] += 1
if int(a[0][0]) > int(a[1][0]):
	(a[0], a[1]) = (a[1], a[0])
	if int(a[1][0]) > int(a[2][0]):
		(a[1], a[2]) = (a[2], a[1])
		if int(a[0][0]) > int(a[1][0]):
			(a[0], a[1]) = (a[1], a[0])
elif int(a[1][0]) > int(a[2][0]):
	(a[1], a[2]) = (a[2], a[1])
	if int(a[0][0]) > int(a[1][0]):
		(a[0], a[1]) = (a[1], a[0])
if a[0] == a[1] and a[1] == a[2]:
	print(0)
elif a[0][1] == a[1][1] and a[1][1] == a[2][1]:
	if int(a[1][0]) - int(a[0][0]) == 1:
		if int(a[2][0]) - int(a[1][0]) == 1:
			print(0)
		else:
			print(1)
	elif int(a[2][0]) - int(a[1][0]) == 1:
		print(1)
	elif int(a[2][0]) - int(a[1][0]) == 0 or int(a[1][0]) - int(a[0][0]) == 0:
		print(1)
	elif int(a[1][0]) - int(a[0][0]) == 2 or int(a[2][0]) - int(a[1][0]) == 2:
		print(1)
	else:
		print(2)
elif a[0][1] == a[1][1]:
	if int(a[1][0]) - int(a[0][0]) == 1:
		print(1)
	elif int(a[1][0]) - int(a[0][0]) == 2:
		print(1)
	elif int(a[1][0]) - int(a[0][0]) == 0:
		print(1)
	else:
		print(2)
elif a[1][1] == a[2][1]:
	if int(a[2][0]) - int(a[1][0]) == 1:
		print(1)
	elif int(a[2][0]) - int(a[1][0]) == 2:
		print(1)
	elif int(a[2][0]) - int(a[1][0]) == 0:
		print(1)
	else:
		print(2)
elif a[0][1] == a[2][1]:
	if int(a[2][0]) - int(a[0][0]) == 1:
		print(1)
	elif int(a[2][0]) - int(a[0][0]) == 2:
		print(1)
	elif int(a[2][0]) - int(a[0][0]) == 0:
		print(1)
	else:
		print(2)
else:
	print(2)


import sys
input = sys.stdin.readline
A = [str(i) for i in input().split()]
ans = 2
S = []
if A[0] == A[1] and A[1] == A[2]:
	ans = 0
else:
	for i in range(3):
		S.append(A[i][1])
	if S[0] == S[1] and S[1] == S[2]:
		N = []
		for i in range(3):
			N.append(int(A[i][0]))
		N.sort()
		if N[1] == N[0] + 1 and N[2] == N[1] + 1:
			ans = 0
	if S[0] == S[1]:
		(a0, a1) = (int(A[0][0]), int(A[1][0]))
		if abs(a0 - a1) <= 2:
			ans = min(1, ans)
	if S[1] == S[2]:
		(a1, a2) = (int(A[1][0]), int(A[2][0]))
		if abs(a1 - a2) <= 2:
			ans = min(1, ans)
	if S[2] == S[0]:
		(a2, a0) = (int(A[2][0]), int(A[0][0]))
		if abs(a2 - a0) <= 2:
			ans = min(1, ans)
print(ans)


l = list(map(str, input().split()))
m = 0
s = 0
p = 0
for i in range(3):
	if l[i][1] == 's':
		s += 1
	elif l[i][1] == 'm':
		m += 1
	else:
		p += 1
if m == 1 and p == 1 and (s == 1):
	print(2)
elif m == 2:
	a = []
	for i in range(3):
		if l[i][1] == 'm':
			a.append(l[i][0])
	a.sort()
	if int(a[1]) == int(a[0]) + 1 or int(a[0]) == int(a[1]) or int(a[1]) == int(a[0]) + 2:
		print(1)
	else:
		print(2)
elif s == 2:
	a = []
	for i in range(3):
		if l[i][1] == 's':
			a.append(l[i][0])
	a.sort()
	if int(a[1]) == int(a[0]) + 1 or int(a[0]) == int(a[1]) or int(a[1]) == int(a[0]) + 2:
		print(1)
	else:
		print(2)
elif p == 2:
	a = []
	for i in range(3):
		if l[i][1] == 'p':
			a.append(l[i][0])
	a.sort()
	if int(a[1]) == int(a[0]) + 1 or int(a[0]) == int(a[1]) or int(a[1]) == int(a[0]) + 2:
		print(1)
	else:
		print(2)
elif m == 3:
	a = []
	for i in range(3):
		a.append(l[i][0])
	a.sort()
	c = 0
	d = 0
	e = 0
	for i in range(2):
		if int(a[i]) == int(a[i + 1]) - 1:
			c += 1
		if int(a[i]) == int(a[i + 1]) - 2:
			e = 1
		if int(a[i]) == int(a[i + 1]):
			d += 1
	print(min(min(2 - c, 2 - d), 2 - e))
elif s == 3:
	a = []
	for i in range(3):
		a.append(l[i][0])
	a.sort()
	c = 0
	d = 0
	e = 0
	for i in range(2):
		if int(a[i]) == int(a[i + 1]) - 1:
			c += 1
		if int(a[i]) == int(a[i + 1]) - 2:
			e = 1
		if int(a[i]) == int(a[i + 1]):
			d += 1
	print(min(min(2 - c, 2 - d), 2 - e))
elif p == 3:
	a = []
	for i in range(3):
		a.append(l[i][0])
	a.sort()
	c = 0
	d = 0
	e = 0
	for i in range(2):
		if int(a[i]) == int(a[i + 1]) - 1:
			c += 1
		if int(a[i]) == int(a[i + 1]) - 2:
			e = 1
		if int(a[i]) == int(a[i + 1]):
			d += 1
	print(min(min(2 - c, 2 - d), 2 - e))


k = {'m': [0] * 9, 's': [0] * 9, 'p': [0] * 9}
p = 1
a = list(map(str, input().split()))
for i in a:
	k[i[1]][int(i[0]) - 1] += 1
for j in k:
	for i in range(7):
		if k[j][i] == 2 or k[j][i + 1] == 2 or k[j][i + 2] == 2:
			p = max(2, p)
			continue
		x = k[j][i] + k[j][i + 1] + k[j][i + 2]
		p = max(p, x)
print(3 - p)


class Mahjong:

	def requiredTileCount(self):
		mahjong.costOfMentsu()
		mahjong.costOfKoutsu()
		return min(self.costM, self.costK)

	def costOfMentsu(self):
		cost = 3
		for suite in ['m', 'p', 's']:
			for digit in range(1, 10):
				cost = min(cost, 3 - self.tiles[suite][digit])
		self.costM = cost

	def costOfKoutsu(self):
		cost = 3
		for suite in ['m', 'p', 's']:
			for index in range(1, 8):
				target = self.tiles[suite][index:index + 3]
				cost = min(cost, self.count_zeros(target))
		self.costK = cost

	def count_zeros(self, listy):
		count = 0
		for i in range(len(listy)):
			if listy[i] == 0:
				count += 1
		return count

	def __init__(self, hand):
		self.tiles = {}
		for suite in ['m', 'p', 's']:
			self.tiles[suite] = [0] * 10
		for index in [0, 1, 2]:
			(value, key) = list(hand.pop(0))
			self.tiles[key][int(value)] += 1
		(self.costM, self.costK) = (3, 3)
mahjong = Mahjong(list(input().split(' ')))
print(mahjong.requiredTileCount())


mast = {'m': 0, 'p': 1, 's': 2}
cd = input().split()
ms = {}
pd = {}
for c in cd:
	x = int(c[0])
	y = mast[c[1]]
	ms[x] = ms.get(x, [])
	ms[x].append(y)
	pd[y] = pd.get(y, [])
	pd[y].append(x)
rm = 2
for (k, v) in ms.items():
	if len(v) == 2:
		if v[0] == v[1]:
			rm = min(rm, 1)
	elif len(v) == 3:
		if v[0] == v[1] and v[1] == v[2] and (v[0] == v[2]):
			rm = min(rm, 0)
		elif v[0] != v[1] and v[1] != v[2] and (v[0] != v[2]):
			pass
		elif v[0] == v[1] or v[1] == v[2] or v[0] == v[2]:
			rm = min(rm, 1)
for (k, v) in pd.items():
	v.sort()
	if len(v) == 2:
		if v[0] - v[1] == -1 or v[0] - v[1] == -2:
			rm = min(rm, 1)
	elif len(v) == 3:
		if v[2] - v[1] == 1 and v[1] - v[0] == 1:
			rm = min(rm, 0)
		elif v[1] - v[0] == 1 or v[1] - v[0] == 2:
			rm = min(rm, 1)
		elif v[2] - v[1] == 1 or v[2] - v[1] == 2:
			rm = min(rm, 1)
print(rm)


l = input().split()
l.sort()
if l[0] == l[1] == l[2]:
	print(0)
elif l[0][1] == l[1][1] == l[2][1]:
	if int(l[0][0]) - int(l[1][0]) == int(l[1][0]) - int(l[2][0]) == -1:
		print(0)
	elif int(l[0][0]) - int(l[1][0]) >= -2 or int(l[1][0]) - int(l[2][0]) >= -2 or int(l[0][0]) - int(l[2][0]) >= -2:
		print(1)
	else:
		print(2)
elif l[0][1] == l[1][1]:
	if 0 <= int(l[1][0]) - int(l[0][0]) <= 2:
		print(1)
	else:
		print(2)
elif l[2][1] == l[1][1]:
	if 0 <= int(l[2][0]) - int(l[1][0]) <= 2:
		print(1)
	else:
		print(2)
elif l[2][1] == l[0][1]:
	if 0 <= int(l[2][0]) - int(l[0][0]) <= 2:
		print(1)
	else:
		print(2)
else:
	print(2)


import sys

def splitTiles(a):
	return [list(filter(lambda x: x[1] == 's', a)), list(filter(lambda x: x[1] == 'p', a)), list(filter(lambda x: x[1] == 'm', a))]

def missingElements(a):
	if len(a) == 0:
		return 2
	return min(map(lambda i: 2 - (1 if (i[0] + 1, i[1]) in a else 0) - (1 if (i[0] + 2, i[1]) in a else 0), a))
tiles = list(map(lambda x: (int(x[0]), x[1]), sys.stdin.readline().strip().split()))
if tiles[0] == tiles[1] and tiles[1] == tiles[2]:
	print('0')
	exit()
if tiles[0] == tiles[1] or tiles[1] == tiles[2] or tiles[0] == tiles[2]:
	print('1')
	exit()
print(min(map(missingElements, splitTiles(tiles))))


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
elif 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)


tiles = input().split()
s = []
m = []
p = []
for i in tiles:
	if i[1] == 's':
		s.append(int(i[0]))
	elif i[1] == 'p':
		p.append(int(i[0]))
	else:
		m.append(int(i[0]))
s.sort()
m.sort()
p.sort()
num_s = len(s)
num_p = len(p)
num_m = len(m)
if num_s == 3:
	if len(set(s)) == 1:
		print(0)
	elif len(set(s)) == 2:
		print(1)
	elif s[0] == s[1] - 1:
		if s[1] == s[2] - 1:
			print(0)
		else:
			print(1)
	elif s[0] < s[1] - 2:
		if s[1] == s[2] - 1 or s[1] == s[2] - 2:
			print(1)
		else:
			print(2)
	else:
		print(1)
elif num_m == 3:
	if len(set(m)) == 1:
		print(0)
	elif len(set(m)) == 2:
		print(1)
	elif m[0] == m[1] - 1:
		if m[1] == m[2] - 1:
			print(0)
		else:
			print(1)
	elif m[0] < m[1] - 2:
		if m[1] == m[2] - 1 or m[1] == m[2] - 2:
			print(1)
		else:
			print(2)
	else:
		print(1)
elif num_p == 3:
	if len(set(p)) == 1:
		print(0)
	elif len(set(p)) == 2:
		print(1)
	elif p[0] == p[1] - 1:
		if p[1] == p[2] - 1:
			print(0)
		else:
			print(1)
	elif p[0] < p[1] - 2:
		if p[1] == p[2] - 1 or p[1] == p[2] - 2:
			print(1)
		else:
			print(2)
	else:
		print(1)
elif num_s == 2:
	if len(set(s)) == 1:
		print(1)
	elif s[0] == s[1] - 1 or s[0] == s[1] - 2:
		print(1)
	else:
		print(2)
elif num_m == 2:
	if len(set(m)) == 1:
		print(1)
	elif m[0] == m[1] - 1 or m[0] == m[1] - 2:
		print(1)
	else:
		print(2)
elif num_p == 2:
	if len(set(p)) == 1:
		print(1)
	elif p[0] == p[1] - 1 or p[0] == p[1] - 2:
		print(1)
	else:
		print(2)
else:
	print(2)


def func(arr):
	if len(arr) == 3:
		if arr[0] == arr[1] and arr[1] == arr[2]:
			return 0
		elif arr[1] == arr[0] + 1 and arr[2] == arr[0] + 2:
			return 0
		elif arr[0] == arr[1] or arr[1] == arr[2]:
			return 1
		elif arr[0] == arr[1] - 1 or arr[2] == arr[1] + 1:
			return 1
		elif arr[0] == arr[1] - 2 or arr[2] == arr[1] + 2:
			return 1
		else:
			return 2
	elif len(arr) == 2:
		if arr[0] == arr[1]:
			return 1
		elif arr[0] == arr[1] - 1 or arr[0] == arr[1] - 2:
			return 1
		else:
			return 2
	elif len(arr) == 1:
		return 2
	else:
		return 3
arr1 = []
arr2 = []
arr3 = []
arr = list(map(str, input().split()))
for i in range(3):
	if arr[i][1] == 'm':
		arr1.append(int(arr[i][0]))
	elif arr[i][1] == 'p':
		arr2.append(int(arr[i][0]))
	else:
		arr3.append(int(arr[i][0]))
arr1.sort()
arr2.sort()
arr3.sort()
ans = 2
if len(arr1) == 1 and len(arr2) == 1 and (len(arr3) == 1):
	print(2)
else:
	if len(arr1) > 1:
		ans = min(ans, func(arr1))
	elif len(arr2) > 1:
		ans = min(ans, func(arr2))
	elif len(arr3) > 1:
		ans = min(ans, func(arr3))
	print(ans)


from collections import Counter
(a, b, c) = list(map(str, input().split()))
s = [a[1], b[1], c[1]]
t = [a[0], b[0], c[0]]
u = Counter(s)
v = Counter(t)
if len(u.keys()) == 1:
	if len(v.keys()) == 1:
		print(0)
	elif len(v.keys()) == 2:
		print(1)
	else:
		t[0] = int(t[0])
		t[1] = int(t[1])
		t[2] = int(t[2])
		t.sort()
		if t[0] + 1 == t[1] and t[2] - 1 == t[1]:
			print(0)
		elif t[0] + 1 == t[1] or t[2] - 1 == t[1] or t[0] + 2 == t[1]:
			print(1)
		else:
			print(2)
elif len(u.keys()) == 3:
	print(2)
elif len(u.keys()) == 2:
	if a[1] == b[1]:
		k = a
		j = b
	elif a[1] == c[1]:
		k = a
		j = c
	elif b[1] == c[1]:
		k = b
		j = c
	if k[0] == j[0]:
		print(1)
	elif abs(ord(k[0]) - ord(j[0])) == 1 or abs(ord(k[0]) - ord(j[0])) == 2 or abs(ord(k[0]) - ord(j[0])) == 0:
		print(1)
	else:
		print(2)


a = input().split()
n = {}
n['m'] = [0 for i in range(9)]
n['s'] = [0 for i in range(9)]
n['p'] = [0 for i in range(9)]
maxcount = 1
for i in a:
	t = i[1]
	l = int(i[0])
	n[t][l - 1] += 1
	if n[t][l - 1] > maxcount:
		maxcount = n[t][l - 1]
flag = 1
if maxcount == 2 and flag:
	print(1)
	flag = 0
if maxcount == 3 and flag:
	print(0)
	flag = 0
prevcons1 = 0
prevcons2 = 0
flag2 = 0
cons = 0
maxcons = 0
if flag:
	for t in ['m', 's', 'p']:
		prevcons1 = 0
		cons = 0
		for i in range(9):
			prevcons2 = prevcons1
			prevcons1 = cons
			if n[t][i]:
				cons += 1
				if cons == prevcons2:
					flag2 = 1
			else:
				cons = 0
			if cons > maxcons:
				maxcons = cons
if maxcons == 3:
	print(0)
	flag = 0
if maxcons == 2:
	print(1)
	flag = 0
if maxcons == 1 and flag2 == 0:
	print(2)
	flag = 0
if flag and flag2:
	print(1)


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
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
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))


cards = input().split()
c1 = cards[0]
c2 = cards[1]
c3 = cards[2]
if c1 == c2 == c3:
	ans = 0
elif c1 != c3 and c1 == c2 or (c2 != c1 and c2 == c3) or (c2 != c1 and c1 == c3):
	ans = 1
else:
	S = [int(c1[0]), int(c2[0]), int(c3[0])]
	if c1[1] == c2[1] == c3[1] and max(S) - min(S) == 2:
		ans = 0
	elif c1[1] == c2[1] == c3[1]:
		if int(c2[0]) - int(c1[0]) == 1 or int(c1[0]) - int(c2[0]) == 1:
			ans = 1
		elif int(c2[0]) - int(c1[0]) == 2 or int(c1[0]) - int(c2[0]) == 2:
			ans = 1
		elif int(c3[0]) - int(c1[0]) == 1 or int(c1[0]) - int(c3[0]) == 1:
			ans = 1
		elif int(c3[0]) - int(c1[0]) == 2 or int(c1[0]) - int(c3[0]) == 2:
			ans = 1
		elif int(c2[0]) - int(c3[0]) == 1 or int(c3[0]) - int(c2[0]) == 1:
			ans = 1
		elif int(c2[0]) - int(c3[0]) == 2 or int(c3[0]) - int(c2[0]) == 2:
			ans = 1
		else:
			ans = 2
	elif c1[1] == c2[1] and int(c2[0]) - int(c1[0]) == 1 or (c1[1] == c2[1] and int(c1[0]) - int(c2[0]) == 1):
		ans = 1
	elif c1[1] == c2[1] and int(c2[0]) - int(c1[0]) == 2 or (c1[1] == c2[1] and int(c1[0]) - int(c2[0]) == 2):
		ans = 1
	elif c1[1] == c3[1] and int(c3[0]) - int(c1[0]) == 1 or (c1[1] == c3[1] and int(c1[0]) - int(c3[0]) == 1):
		ans = 1
	elif c1[1] == c3[1] and int(c3[0]) - int(c1[0]) == 2 or (c1[1] == c3[1] and int(c1[0]) - int(c3[0]) == 2):
		ans = 1
	elif int(c2[0]) - int(c3[0]) == 1 and c2[1] == c3[1] or (int(c3[0]) - int(c2[0]) == 1 and c2[1] == c3[1]):
		ans = 1
	elif int(c2[0]) - int(c3[0]) == 2 and c2[1] == c3[1] or (int(c3[0]) - int(c2[0]) == 2 and c2[1] == c3[1]):
		ans = 1
	else:
		ans = 2
print(ans)


z = sorted([int(i[0]) + ord(i[1]) * 9 for i in map(str, input().split())])
if len(set(z)) == 1 or (z[0] == z[1] - 1 and z[1] == z[2] - 1):
	print(0)
elif (z[0] == z[1] or z[1] == z[2]) or (z[1] - z[0] in [1, 2] or z[2] - z[1] in [1, 2]):
	print(1)
else:
	print(2)


def find():
	s = input()
	s = s.split()
	d = {'m': [0 for i in range(10)], 'p': [0 for i in range(10)], 's': [0 for i in range(10)]}
	for e in s:
		d[e[1]][int(e[0])] += 1
	res = 2
	for e in d:
		e = d[e]
		for i in range(10):
			if e[i] == 3:
				print(0)
				exit()
			elif e[i] == 2:
				if res > 1:
					res = 1
			if i < 8:
				if e[i] > 0:
					if e[i + 1] > 0 and e[i + 2] > 0:
						print(0)
						exit()
					elif e[i + 1] > 0 or e[i + 2] > 0:
						if res > 1:
							res = 1
			elif i < 9:
				if e[i] > 0 and e[i + 1] > 0:
					if res > 1:
						res = 1
	return res
a = find()
print(a)


cards = list(input().split())
lm = [0] * 9
lp = [0] * 9
ls = [0] * 9
for item in cards:
	if item[1] == 'm':
		lm[int(item[0]) - 1] += 1
	elif item[1] == 'p':
		lp[int(item[0]) - 1] += 1
	else:
		ls[int(item[0]) - 1] += 1
if max(lm) == 3 or max(lp) == 3 or max(ls) == 3:
	print(0)
else:
	flag = 0

	def seq_checker(li):
		flag = 0
		for i in range(9):
			if flag == 0:
				if lm[i] == 1:
					flag = 1
			elif lm[i] == 1:
				flag += 1
			else:
				break
		return flag
	if seq_checker(lm) == 3 or seq_checker(lp) == 3 or seq_checker(ls) == 3:
		print(0)
	elif max(lm) == 2 or max(lp) == 2 or max(ls) == 2:
		print(1)
	else:
		m = 0
		for i in range(0, 7):
			m = max(sum(lm[i:i + 3]), sum(lp[i:i + 3]), sum(ls[i:i + 3]), m)
		print(3 - m)


(t1, t2, t3) = input().split()
ans = 2
if t1 == t2 or t2 == t3 or t3 == t1:
	if t1 == t2 == t3:
		ans = 0
	else:
		ans = 1
aaa = []
for i in range(10):
	for j in range(10):
		for k in range(10):
			if k - j == j - i == 1:
				aaa.append({i, j, k})
if t1[1] == t2[1] == t3[1] and {int(t1[0]), int(t2[0]), int(t3[0])} in aaa:
	ans = 0
elif t1[1] == t2[1] and (abs(int(t1[0]) - int(t2[0])) == 1 or abs(int(t1[0]) - int(t2[0])) == 2) or (t1[1] == t3[1] and (abs(int(t1[0]) - int(t3[0])) == 1 or abs(int(t1[0]) - int(t3[0])) == 2)) or (t3[1] == t2[1] and (abs(int(t3[0]) - int(t2[0])) == 1 or abs(int(t3[0]) - int(t2[0])) == 2)):
	ans = min(1, ans)
print(ans)


s = input().split()
l = []
s.sort()
for i in s:
	l.append(int(i[0]))
	l.append(i[1])
if l[0] == l[2] and l[1] == l[3]:
	if l[0] == l[4] and l[1] == l[5]:
		print(0)
	else:
		print(1)
elif l[4] == l[2] and l[5] == l[3]:
	print(1)
elif l[0] + 1 == l[2] and l[1] == l[3]:
	if l[2] + 1 == l[4] and l[3] == l[5]:
		print(0)
	else:
		print(1)
elif l[0] + 2 == l[2] and l[1] == l[3]:
	print(1)
elif l[2] + 1 == l[4] and l[5] == l[3]:
	print(1)
elif l[2] + 2 == l[4] and l[5] == l[3]:
	print(1)
elif l[0] + 1 == l[4] and l[1] == l[5]:
	print(1)
elif l[0] + 2 == l[4] and l[1] == l[5]:
	print(1)
else:
	print(2)


(a, b, c) = input().split()
(a, b, c) = sorted([a, b, c])
A = [a, b, c]
A = set(A)
if len(A) == 1:
	print(0)
	exit()
if len(A) == 2:
	print(1)
	exit()
if a[1] == b[1] and b[1] == c[1]:
	if a[0] == b[0] and b[0] == c[0]:
		print(0)
	elif int(b[0]) == int(a[0]) + 1 and int(c[0]) == int(b[0]) + 1:
		print(0)
	elif int(b[0]) == int(a[0]) + 1 or int(c[0]) == int(b[0]) + 1:
		print(1)
	elif int(b[0]) - int(a[0]) == 2 or int(c[0]) - int(b[0]) == 2:
		print(1)
	else:
		print(2)
elif a[1] == b[1]:
	if int(b[0]) - int(a[0]) <= 2:
		print(1)
	else:
		print(2)
elif b[1] == c[1]:
	if int(c[0]) - int(b[0]) <= 2:
		print(1)
	else:
		print(2)
elif a[1] == c[1]:
	if int(c[0]) - int(a[0]) <= 2:
		print(1)
	else:
		print(2)
else:
	print(2)


arr = input().split()
flag = 0
t1 = arr[0]
t2 = arr[1]
t3 = arr[2]
if t1[1] == t2[1] and t1[1] == t3[1]:
	arr_num = [int(t1[0]), int(t2[0]), int(t3[0])]
	arr_num.sort()
	if arr_num[0] == arr_num[1] - 1 and arr_num[1] == arr_num[2] - 1:
		print(0)
		flag = 1
if t1 == t2 and t1 == t3 and (flag == 0):
	print(0)
	flag = 1
if t1[1] == t2[1] and (abs(int(t1[0]) - int(t2[0])) == 1 or t1[0] == t2[0] or abs(int(t1[0]) - int(t2[0])) == 2) and (flag == 0):
	print(1)
	flag = 1
if t1[1] == t3[1] and (abs(int(t1[0]) - int(t3[0])) == 1 or t1[0] == t3[0] or abs(int(t1[0]) - int(t3[0])) == 2) and (flag == 0):
	print(1)
	flag = 1
if t2[1] == t3[1] and (abs(int(t2[0]) - int(t3[0])) == 1 or t2[0] == t3[0] or abs(int(t2[0]) - int(t3[0])) == 2) and (flag == 0):
	print(1)
	flag = 1
if flag == 0:
	print(2)


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 = {}
	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()


s = input().rstrip().split(' ')
l = []
q = []
w = []
S = []
D = []
for i in range(0, len(s)):
	t = list(s[i])
	if t[1] == 's':
		l.append(int(t[0]))
	elif t[1] == 'p':
		q.append(int(t[0]))
	else:
		w.append(int(t[0]))
l.sort()
q.sort()
w.sort()
F = []
if len(l) == 0:
	F.append(3)
elif len(l) == 1:
	F.append(2)
elif len(l) == 2:
	F.append(len(list(set(l))))
	if l[0] == l[1] or l[0] == l[1] - 1 or l[0] == l[1] - 2:
		F.append(1)
	else:
		F.append(2)
elif len(l) == 3:
	if len(list(set(l))) == 1:
		F.append(0)
	if len(list(set(l))) == 2:
		F.append(1)
	if len(list(set(l))) == 3:
		F.append(2)
	if l[0] == l[1] - 2 or l[1] == l[2] - 2 or l[0] == l[2] - 2:
		F.append(1)
	if len(list(set(l))) == 1:
		F.append(0)
	if l[0] == l[1] - 1 and l[1] == l[2] - 1:
		F.append(0)
	if l[0] == l[1] - 1 and l[1] != l[2] - 1:
		F.append(1)
	if l[0] != l[1] - 1 and l[1] == l[2] - 1:
		F.append(1)
	if l[0] != l[1] - 1 and l[1] != l[2] - 1:
		F.append(2)
l = q
if len(l) == 0:
	F.append(3)
elif len(l) == 1:
	F.append(2)
elif len(l) == 2:
	F.append(len(list(set(l))))
	if l[0] == l[1] or l[0] == l[1] - 1 or l[0] == l[1] - 2:
		F.append(1)
	else:
		F.append(2)
elif len(l) == 3:
	if len(list(set(l))) == 1:
		F.append(0)
	if len(list(set(l))) == 2:
		F.append(1)
	if len(list(set(l))) == 3:
		F.append(2)
	if l[0] == l[1] - 2 or l[1] == l[2] - 2 or l[0] == l[2] - 2:
		F.append(1)
	if len(list(set(l))) == 1:
		F.append(0)
	if l[0] == l[1] - 1 and l[1] == l[2] - 1:
		F.append(0)
	if l[0] == l[1] - 1 and l[1] != l[2] - 1:
		F.append(1)
	if l[0] != l[1] - 1 and l[1] == l[2] - 1:
		F.append(1)
	if l[0] != l[1] - 1 and l[1] != l[2] - 1:
		F.append(2)
l = w
if len(l) == 0:
	F.append(3)
elif len(l) == 1:
	F.append(2)
elif len(l) == 2:
	F.append(len(list(set(l))))
	if l[0] == l[1] or l[0] == l[1] - 1 or l[0] == l[1] - 2:
		F.append(1)
	else:
		F.append(2)
elif len(l) == 3:
	if len(list(set(l))) == 1:
		F.append(0)
	if len(list(set(l))) == 2:
		F.append(1)
	if len(list(set(l))) == 3:
		F.append(2)
	if l[0] == l[1] - 2 or l[1] == l[2] - 2 or l[0] == l[2] - 2:
		F.append(1)
	if len(list(set(l))) == 1:
		F.append(0)
	if l[0] == l[1] - 1 and l[1] == l[2] - 1:
		F.append(0)
	if l[0] == l[1] - 1 and l[1] != l[2] - 1:
		F.append(1)
	if l[0] != l[1] - 1 and l[1] == l[2] - 1:
		F.append(1)
	if l[0] != l[1] - 1 and l[1] != l[2] - 1:
		F.append(2)
print(min(F))


def main():
	(a, b, c) = input().split()
	s = set([a, b, c])
	if len(s) == 1:
		print(0)
		return
	elif len(s) == 2:
		curNeed = 1
	else:
		curNeed = 2
	lister = [a, b, c]
	lister.sort(key=lambda x: x[0])
	lister.sort(key=lambda x: x[1])
	before = '**'
	counter = 1
	jump = 0
	for now in lister:
		if before[1] == now[1] and int(before[0]) + 1 == int(now[0]):
			counter += 1
		elif before[1] == now[1] and int(before[0]) + 2 == int(now[0]):
			jump = 1
		before = now
	if counter == 3:
		print(0)
		return
	if jump == 1:
		print(1)
		return
	curNeed = min(curNeed, 3 - counter)
	print(curNeed)
	return
main()


def main():
	ss = list(map(str, input().split()))
	for i in range(0, len(ss)):
		ss[i] = ss[i][::-1]
	ss = sorted(ss)
	for i in range(0, len(ss)):
		ss[i] = ss[i][::-1]
	for i in range(0, len(ss) - 2):
		if ss[i] == ss[i + 1] == ss[i + 2]:
			print(0)
			exit(0)
		elif ord(ss[i][0]) + 2 == ord(ss[i + 1][0]) + 1 == ord(ss[i + 2][0]) and ss[i][1] == ss[i + 1][1] == ss[i + 2][1]:
			print(0)
			exit(0)
	for i in range(0, len(ss) - 1):
		if ss[i] == ss[i + 1]:
			print(1)
			exit(0)
		elif (ord(ss[i][0]) + 1 == ord(ss[i + 1][0]) or ord(ss[i][0]) + 2 == ord(ss[i + 1][0])) and ss[i][1] == ss[i + 1][1]:
			print(1)
			exit(0)
	print(2)
main()


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

def is_koutsu(s):
	cnt = 0
	arr = []
	for i in s:
		cnt = 0
		for j in s:
			if i == j:
				cnt += 1
		arr.append(cnt)
	return max(arr)

def is_shuntsu(s):
	cnt = 0
	arr = []
	for i in s:
		cnt = 0
		for j in s:
			for k in s:
				if int(i[0]) + 1 == int(j[0]) and int(i[0]) + 2 == int(k[0]) and (i[1] == j[1]) and (j[1] == k[1]):
					cnt += 1
			arr.append(cnt)
	return max(arr)

def kek(s):
	for i in s:
		for j in s:
			if int(i[0]) + 1 == int(j[0]) and i[1] == j[1]:
				return 2
	return 0

def kek_1(s):
	for i in s:
		for j in s:
			if int(i[0]) + 2 == int(j[0]) and i[1] == j[1]:
				return 2
	return 0
if is_shuntsu(st) == 1:
	print(0)
	exit()
print(min(min(3 - is_koutsu(st), 3 - kek_1(st)), min(3 - is_shuntsu(st), 3 - kek(st))))


d = list(map(str, input().split()))
s = [0] * 9
m = [0] * 9
p = [0] * 9

def kut(l):
	t = max(l)
	if t >= 3:
		return 0
	return 3 - t

def sut(l):
	for i in range(len(l)):
		if l[i] > 1:
			l[i] = 1
	s = ''.join([str(i) for i in l])
	if '111' in s:
		return 0
	elif '11' in s or '101' in s:
		return 1
	elif '1' in s:
		return 2
	else:
		return 3
for i in d:
	if i[1] == 's':
		s[int(i[0]) - 1] += 1
	elif i[1] == 'm':
		m[int(i[0]) - 1] += 1
	else:
		p[int(i[0]) - 1] += 1
l = [0] * 6
l[0] = kut(s)
l[1] = kut(m)
l[2] = kut(p)
l[3] = sut(s)
l[4] = sut(p)
l[5] = sut(m)
t = min(l)
print(t)


import functools

class node(object):

	def __init__(self):
		self.num = 0
		self.c = '0'
p = node()
s = [node() for i in range(3)]

def cmp_new(a, b):
	if a.num == b.num:
		return ord(a.c) - ord(b.c)
	return ord(a.num) - ord(b.num)
(s1, s2, s3) = map(list, input().split())
s[0].num = chr(ord(s1[0]) - ord('0'))
s[1].num = chr(ord(s2[0]) - ord('0'))
s[2].num = chr(ord(s3[0]) - ord('0'))
s[0].c = s1[1]
s[1].c = s2[1]
s[2].c = s3[1]
s.sort(key=functools.cmp_to_key(cmp_new))
ans = 2
if ord(s[0].num) == ord(s[2].num) - 2 and ord(s[1].num) == ord(s[2].num) - 1 and (s[0].c == s[1].c and s[1].c == s[2].c):
	ans = 0
elif s[0].num == s[2].num and s[1].num == s[2].num and (s[0].c == s[1].c and s[1].c == s[2].c):
	ans = 0
elif ord(s[1].num) - ord(s[0].num) == 1 and s[1].c == s[0].c:
	ans = 1
elif s[1].num == s[0].num and s[1].c == s[0].c:
	ans = 1
elif ord(s[2].num) - ord(s[1].num) == 1 and s[2].c == s[1].c:
	ans = 1
elif s[2].num == s[1].num and s[2].c == s[1].c:
	ans = 1
elif ord(s[2].num) - ord(s[0].num) == 2 and s[2].c == s[0].c:
	ans = 1
elif ord(s[1].num) - ord(s[0].num) == 2 and s[1].c == s[0].c:
	ans = 1
elif ord(s[2].num) - ord(s[1].num) == 2 and s[2].c == s[1].c:
	ans = 1
elif ord(s[2].num) - ord(s[0].num) == 1 and s[2].c == s[0].c:
	ans = 1
print(ans)


gi = lambda : list(map(int, input().strip().split()))
l = input().split()
l.sort()
if len(set(l)) == 1:
	print(0)
	exit()
c = l[0][1]
b = int(l[0][0])
flag = True
for e in l:
	if e[1] != c:
		flag = False
		break
for e in l:
	if int(e[0]) != b:
		flag = False
		break
	b += 1
if flag:
	print(0)
	exit()
c = l[0][1]
b = int(l[0][0])
bb = int(l[1][0])
bbb = int(l[2][0])
cc = l[1][1]
ccc = l[2][1]
if c == cc:
	if bb - b <= 2:
		print(1)
		exit()
if c == ccc:
	if bbb - b <= 2:
		print(1)
		exit()
if cc == ccc:
	if bbb - bb <= 2:
		print(1)
		exit()
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)


l = input().split()
if l[0] == l[1] and l[1] == l[2]:
	print(0)
	return

def shuntsu(li):
	li.sort()
	return li[0][1] == li[1][1] and li[1][1] == li[2][1] and (int(li[1][0]) == int(li[0][0]) + 1) and (int(li[2][0]) == int(li[1][0]) + 1)
if shuntsu(l):
	print(0)
	return
for k in l:
	if len([x for x in l if x == k]) > 1:
		print(1)
		return
	if len([x for x in l if x[1] == k[1] and int(x[0]) == int(k[0]) + 1]) != 0:
		print(1)
		return
	if len([x for x in l if x[1] == k[1] and int(x[0]) == int(k[0]) + 2]) != 0:
		print(1)
		return
print(2)


(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)


(m, p, s) = input().split()
sp = [(int(m[0]), m[1]), (int(p[0]), p[1]), (int(s[0]), s[1])]
sp.sort()
g = set()
g.add(m[1])
g.add(p[1])
g.add(s[1])
if m == p and p == s or (sp[2][0] - sp[1][0] == 1 and sp[2][0] - sp[0][0] == 2 and (len(g) == 1)):
	print(0)
elif m == p or p == s or m == s:
	print(1)
elif sp[2][0] - sp[1][0] == 1 and sp[2][1] == sp[1][1]:
	print(1)
elif sp[1][0] - sp[0][0] == 1 and sp[1][1] == sp[0][1]:
	print(1)
elif sp[2][0] - sp[0][0] == 1 and sp[2][1] == sp[0][1]:
	print(1)
elif sp[2][0] - sp[1][0] == 2 and sp[2][1] == sp[1][1]:
	print(1)
elif sp[1][0] - sp[0][0] == 2 and sp[1][1] == sp[0][1]:
	print(1)
elif sp[2][0] - sp[0][0] == 2 and sp[2][1] == sp[0][1]:
	print(1)
else:
	print(2)


(a, b, c) = input().split()
if a == b and b == c:
	print(0)
	exit()
x = sorted([int(a[0]), int(b[0]), int(c[0])])
if (a[1] == b[1] and b[1] == c[1]) and (x[0] + 1 == x[1] and x[1] + 1 == x[2]):
	print(0)
	exit()
if a == b or b == c or a == c:
	print(1)
	exit()
d = {'p': [], 'm': [], 's': []}
d[a[1]].append(a)
d[b[1]].append(b)
d[c[1]].append(c)
ans = 2
flag = 0
for i in d:
	if len(d[i]) == 2:
		x = sorted([int(d[i][0][0]), int(d[i][1][0])])
		if x[1] - x[0] <= 2:
			ans = min(ans, 1)
	elif len(d[i]) == 3:
		x = sorted([int(d[i][0][0]), int(d[i][1][0]), int(d[i][2][0])])
		if x[1] - x[0] <= 2 or x[2] - x[1] <= 2:
			ans = min(ans, 1)
print(ans)


import sys
import math
input = sys.stdin.readline
(a, b, c) = input().split()
s = []
p = []
m = []
if a[1] == 'p':
	p.append(int(a[0]))
elif a[1] == 's':
	s.append(int(a[0]))
else:
	m.append(int(a[0]))
if b[1] == 'p':
	p.append(int(b[0]))
elif b[1] == 's':
	s.append(int(b[0]))
else:
	m.append(int(b[0]))
if c[1] == 'p':
	p.append(int(c[0]))
elif c[1] == 's':
	s.append(int(c[0]))
else:
	m.append(int(c[0]))
s.sort()
p.sort()
m.sort()
cur = 2
if len(s) == 3:
	if s[0] == s[1] and s[1] == s[2]:
		cur = 0
	elif s[0] == s[1] or s[1] == s[2]:
		cur = 1
	elif s[0] + 1 == s[1] and s[1] + 1 == s[2]:
		cur = 0
	elif s[0] + 1 == s[1] or s[1] + 1 == s[2]:
		cur = 1
	elif s[0] + 2 == s[1] or s[1] + 2 == s[2]:
		cur = 1
	else:
		cur = 2
elif len(s) == 2:
	if s[0] == s[1]:
		cur = 1
	elif s[0] + 1 == s[1]:
		cur = 1
	elif s[0] + 2 == s[1]:
		cur = 1
	else:
		cur = 2
else:
	cur = 2
x = 2
if len(p) == 3:
	if p[0] == p[1] and p[1] == p[2]:
		x = 0
	elif p[0] == p[1] or p[1] == p[2]:
		x = 1
	elif p[0] + 1 == p[1] and p[1] + 1 == p[2]:
		x = 0
	elif p[0] + 1 == p[1] or p[1] + 1 == p[2]:
		x = 1
	elif p[0] + 2 == p[1] or p[1] + 2 == p[2]:
		x = 1
	else:
		x = 2
elif len(p) == 2:
	if p[0] == p[1]:
		x = 1
	elif p[0] + 1 == p[1]:
		x = 1
	elif p[0] + 2 == p[1]:
		x = 1
	else:
		x = 2
else:
	x = 2
y = 2
if len(m) == 3:
	if m[0] == m[1] and m[1] == m[2]:
		y = 0
	elif m[0] == m[1] or m[1] == m[2]:
		y = 1
	elif m[0] + 1 == m[1] and m[1] + 1 == m[2]:
		y = 0
	elif m[0] + 1 == m[1] or m[1] + 1 == m[2]:
		y = 1
	elif m[0] + 2 == m[1] or m[1] + 2 == m[2]:
		y = 1
	else:
		y = 2
elif len(m) == 2:
	if m[0] == m[1]:
		y = 1
	elif m[0] + 1 == m[1]:
		y = 1
	elif m[0] + 2 == m[1]:
		y = 1
	else:
		y = 2
else:
	y = 2
print(min(cur, x, y))


s = input().split(' ')
s1 = []
p1 = []
m1 = []
for i in s:
	if i[1] == 'm':
		m1.append(int(i[0]))
	elif i[1] == 'p':
		p1.append(int(i[0]))
	else:
		s1.append(int(i[0]))
s1 = sorted(s1)
p1 = sorted(p1)
m1 = sorted(m1)
if len(m1) == len(s1) == len(p1) == 1:
	print(2)
elif len(m1) >= 2:
	if len(m1) > 2 and (abs(m1[0] - m1[1]) <= 1 or abs(m1[1] - m1[2]) <= 1):
		if abs(m1[0] - m1[1]) == abs(m1[2] - m1[1]):
			print(0)
		else:
			print(1)
	elif abs(m1[0] - m1[1]) <= 1 and len(m1) == 2:
		print(1)
	elif abs(m1[0] - m1[1]) == 2:
		print(1)
	else:
		print(2)
elif len(s1) >= 2:
	if len(s1) > 2 and (abs(s1[0] - s1[1]) <= 1 or abs(s1[1] - s1[2]) <= 1):
		if abs(s1[0] - s1[1]) == abs(s1[2] - s1[1]):
			print(0)
		else:
			print(1)
	elif abs(s1[0] - s1[1]) <= 1 and len(s1) == 2:
		print(1)
	elif abs(s1[0] - s1[1]) == 2:
		print(1)
	else:
		print(2)
elif len(p1) > 2 and (abs(p1[0] - p1[1]) <= 1 or abs(p1[1] - p1[2]) <= 1):
	if abs(p1[0] - p1[1]) == abs(p1[2] - p1[1]):
		print(0)
	else:
		print(1)
elif abs(p1[0] - p1[1]) <= 1 and len(p1) == 2:
	print(1)
elif abs(p1[0] - p1[1]) == 2:
	print(1)
else:
	print(2)


from collections import defaultdict

def main():
	A = list(input().split())
	B = sorted(A, key=lambda x: int(x[0]))
	m = defaultdict(list)
	for i in B:
		m[i[1]].append(int(i[0]))
	maxCount = 0
	for i in m:
		count1 = 0
		for j in range(len(m[i]) - 1):
			if m[i][j] == m[i][j + 1]:
				count1 += 1
			else:
				count1 = 0
			if count1 > maxCount:
				maxCount = count1
			if count1 == 2:
				print(0)
				return
	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
	if maxCount == 0:
		for i in m:
			for j in range(len(m[i]) - 1):
				if abs(m[i][j] - m[i][j + 1]) == 2:
					print(1)
					return
	if len(A) == 0:
		print(3)
	else:
		print(2 - maxCount)
main()


import sys
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)


import random as random

def quicksort(nums):
	if len(nums) <= 1:
		return nums
	else:
		q = random.choice(nums)
	l_nums = [n for n in nums if n < q]
	e_nums = [q] * nums.count(q)
	b_nums = [n for n in nums if n > q]
	return quicksort(l_nums) + e_nums + quicksort(b_nums)
l = list(input().split(' '))
l = quicksort(l)
Answ = ''
if l[0] == l[1] == l[2]:
	Answ = '0'
elif l[0][1] == l[1][1] == l[2][1] and int(l[0][0]) + 1 == int(l[1][0]) == int(l[2][0]) - 1:
	Answ = '0'
elif l[0] == l[1] or l[1] == l[2]:
	Answ = '1'
elif l[0][1] == l[1][1] and int(l[0][0]) + 1 == int(l[1][0]):
	Answ = '1'
elif l[2][1] == l[1][1] and int(l[1][0]) + 1 == int(l[2][0]):
	Answ = '1'
elif l[2][1] == l[0][1] and int(l[0][0]) + 1 == int(l[2][0]):
	Answ = '1'
elif l[2][1] == l[0][1] and int(l[0][0]) + 2 == int(l[2][0]):
	Answ = '1'
elif l[1][1] == l[0][1] and int(l[0][0]) + 2 == int(l[1][0]):
	Answ = '1'
elif l[2][1] == l[1][1] and int(l[1][0]) + 2 == int(l[2][0]):
	Answ = '1'
else:
	Answ = '2'
print(Answ)


s = list(map(lambda x: (int(x[0]), x[1]), input().split()))
st = list(set([x for (_, x) in s]))
best = 2
for a in st:
	mp = sorted(map(lambda t: t[0], list(filter(lambda x: x[1] == a, s))))
	if len(mp) == 3 and (mp[0] == mp[1] == mp[2] or (mp[0] + 1 == mp[1] and mp[1] + 1 == mp[2])):
		best = min(best, 0)
	if len(mp) >= 2 and (mp[0] + 1 == mp[1] or mp[0] + 2 == mp[1] or mp[0] == mp[1]) or (len(mp) == 3 and (mp[1] + 1 == mp[2] or mp[1] + 2 == mp[2] or mp[1] == mp[2])):
		best = min(best, 1)
print(best)


import collections
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
	ans = min(ans, 3 - m_sub)
print(ans)


(a, b, c) = input().split()
y = sorted([a[0], b[0], c[0]])
y1 = [int(y[i + 1]) - int(y[i]) for i in range(2)]
y2 = sorted([a[1], b[1], c[1]])
if len(set(y2)) == 1:
	if set(y1) == {0}:
		print(0)
	elif set(y1) == {1}:
		print(0)
	elif 0 in set(y1) or 1 in set(y1) or 2 in set(y1):
		print(1)
	else:
		print(2)
elif len(set(y2)) == 2:
	x = sorted([a, b, c], key=lambda m: m[1])
	if x[0][1] == x[1][1]:
		if int(x[0][0]) - int(x[1][0]) == 0 or abs(int(x[1][0]) - int(x[0][0])) == 1 or abs(int(x[1][0]) - int(x[0][0])) == 2:
			print(1)
		else:
			print(2)
	elif x[1][1] == x[2][1]:
		if int(x[1][0]) - int(x[2][0]) == 0 or abs(int(x[2][0]) - int(x[1][0])) == 1 or abs(int(x[2][0]) - int(x[1][0])) == 2:
			print(1)
		else:
			print(2)
	else:
		print(2)
else:
	print(2)


arr = input().split()
arr.sort()
m = []
p = []
s = []
for i in range(3):
	if arr[i][-1] == 's':
		s.append(int(arr[i][0]))
	if arr[i][-1] == 'm':
		m.append(int(arr[i][0]))
	if arr[i][-1] == 'p':
		p.append(int(arr[i][0]))
if len(m) == 3 and m[0] + 1 == m[1] and (m[1] + 1 == m[2]):
	print(0)
elif len(m) == 3 and m[0] == m[1] and (m[1] == m[2]):
	print(0)
elif len(s) == 3 and s[0] == s[1] and (s[1] == s[2]):
	print(0)
elif len(p) == 3 and p[0] == p[1] and (p[1] == p[2]):
	print(0)
elif len(p) == 3 and p[0] + 1 == p[1] and (p[1] + 1 == p[2]):
	print(0)
elif len(s) == 3 and s[0] + 1 == s[1] and (s[1] + 1 == s[2]):
	print(0)
elif len(s) == 3 and (s[0] == s[1] or s[1] == s[2] or s[0] + 1 == s[1] or (s[1] + 1 == s[2]) or (s[0] + 2 == s[2]) or (s[0] + 2 == s[1]) or (s[1] + 2 == s[2])):
	print(1)
elif len(m) == 3 and (m[0] == m[1] or m[1] == m[2] or m[0] + 1 == m[1] or (m[1] + 1 == m[2]) or (m[0] + 2 == m[2]) or (m[0] + 2 == m[1]) or (m[1] + 2 == m[2])):
	print(1)
elif len(p) == 3 and (p[0] == p[1] or p[1] == p[2] or p[0] + 1 == p[1] or (p[1] + 1 == p[2]) or (p[0] + 2 == p[2]) or (p[0] + 2 == p[1]) or (p[1] + 2 == p[2])):
	print(1)
elif len(m) == 2 and (m[0] == m[1] or m[0] + 1 == m[1] or m[0] + 2 == m[1]):
	print(1)
elif len(s) == 2 and (s[0] == s[1] or s[0] + 1 == s[1] or s[0] + 2 == s[1]):
	print(1)
elif len(p) == 2 and (p[0] == p[1] or p[0] + 1 == p[1] or p[0] + 2 == p[1]):
	print(1)
else:
	print(2)


def ism(a, b, c):
	return a == b and b == c

def isk(a, b, c):
	x = [a, b, c]
	x.sort()
	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[1][0]) + 1 == int(x[2][0]):
			return 1
	return 0
(a, b, c) = input().split()
x = [a, b, c]
typem = []
types = []
typep = []
(m, s, p) = (0, 0, 0)
for i in x:
	if i[1] == 'm':
		m += 1
		typem.append(i)
	elif i[1] == 's':
		s += 1
		types.append(i)
	elif i[1] == 'p':
		p += 1
		typep.append(i)
ans = 0
done = 0
if isk(a, b, c) or ism(a, b, c):
	ans = 0
	done = 1
if done == 0 and a == b and (b == c):
	ans = 0
	done = 1
elif done == 0 and a == b:
	ans = 1
	done = 1
elif done == 0 and b == c:
	ans = 1
	done = 1
elif done == 0 and a == c:
	ans = 1
	done = 1
if done == 0 and m >= 2:
	typem.sort()
	for i in range(len(typem) - 1):
		if abs(int(typem[i][0]) - int(typem[i + 1][0])) <= 2 and abs(int(typem[i][0]) - int(typem[i + 1][0])) > 0:
			ans = 1
			done = 1
if done == 0 and s >= 2:
	types.sort()
	for i in range(len(types) - 1):
		if abs(int(types[i][0]) - int(types[i + 1][0])) <= 2 and abs(int(types[i][0]) - int(types[i + 1][0])) > 0:
			ans = 1
			done = 1
if done == 0 and p >= 2:
	typep.sort()
	for i in range(len(typep) - 1):
		if abs(int(typep[i][0]) - int(typep[i + 1][0])) <= 2 and abs(int(typep[i][0]) - int(typep[i + 1][0])) > 0:
			ans = 1
			done = 1
if done == 0:
	ans = 2
	done = 1
print(ans)


from collections import defaultdict

def is123(List):
	List.sort()
	if List[1] - List[0] == 1 and List[2] - List[1] == 1:
		return True
	else:
		return False

def is139(List):
	List.sort()
	if List[1] - List[0] <= 2 or List[2] - List[1] <= 2:
		return True
	return False

def is1123(List):
	List.sort()
	if List[1] - List[0] <= 2:
		return True
	return False
(a, b, c) = map(str, input().split())
Number = [int(a[0]), int(b[0]), int(c[0])]
Char = [a[1], b[1], c[1]]
Dict = defaultdict(list)
Dict[Char[0]].append(Number[0])
Dict[Char[1]].append(Number[1])
Dict[Char[2]].append(Number[2])
if (len(set(Number)) == 1 or is123(Number)) and len(set(Char)) == 1:
	print(0)
elif len(set(Char)) == 1 and is139(Number):
	print(1)
elif len(set(Char)) == 1 and (not is139(Number)):
	print(2)
elif len(set(Char)) == 3:
	print(2)
elif len(set(Char)) == 2:
	for i in Dict.keys():
		if len(Dict[i]) == 2:
			P = Dict[i]
			break
	if is1123(P):
		print(1)
	else:
		print(2)


a = input().split()
st = set([])
cnt = [[0 for i in range(9)] for i in range(3)]
for e in a:
	cnt['mps'.index(e[1])][int(e[0]) - 1] = 1
	st.add(e)
answ = len(st) - 1
for i in range(3):
	for j in range(7):
		answ = min(answ, 3 - sum(cnt[i][j:j + 3]))
print(answ)


(a, b, c) = input().split(' ')
anum = int(a[0])
achar = a[1]
bnum = int(b[0])
bchar = b[1]
cnum = int(c[0])
cchar = c[1]
arr = []
arr.append(a)
arr.append(b)
arr.append(c)
acount = arr.count(a)
bcount = arr.count(b)
ccount = arr.count(c)
arval = []
arval.append(anum)
arval.append(bnum)
arval.append(cnum)
archar = []
archar.append(achar)
archar.append(bchar)
archar.append(cchar)
(arval, archar) = (list(t) for t in zip(*sorted(zip(arval, archar))))
if acount == 3 or bcount == 3 or ccount == 3:
	print(0)
elif arval[0] + 2 == arval[1] + 1 == arval[2] and archar[0] == archar[1] == archar[2]:
	print(0)
elif acount == 2 or bcount == 2 or ccount == 2:
	print(1)
elif arval[0] + 1 == arval[1] and archar[0] == archar[1] or (arval[0] + 1 == arval[2] and archar[0] == archar[2]) or (arval[0] + 2 == arval[2] and archar[0] == archar[2]) or (arval[0] + 2 == arval[1] and archar[0] == archar[1]) or (arval[1] + 2 == arval[2] and archar[1] == archar[2]) or (arval[1] + 1 == arval[2] and archar[1] == archar[2]):
	print(1)
else:
	print(2)


(x, y, z) = input().split()
p = []
n1 = int(x[0])
n2 = int(y[0])
n3 = int(z[0])
p.append(int(n1))
p.append(int(n2))
p.append(int(n3))
p.sort()
t1 = x[1]
t2 = y[1]
t3 = z[1]
if t1 == t2 == t3 and n1 == n2 == n3 or (t1 == t2 == t3 and p[1] == p[0] + 1 and (p[2] == p[0] + 2)):
	print(0)
elif (t1 == t2 and n1 == n2 or (t2 == t3 and n2 == n3) or (t1 == t3 and n1 == n3)) or (t1 == t2 and (n2 == n1 + 1 or n2 == n1 + 2 or n1 == n2 + 1 or (n1 == n2 + 2)) or (t2 == t3 and (n3 == n2 + 1 or n3 == n2 + 2 or n2 == n3 + 1 or (n2 == n3 + 2))) or (t1 == t3 and (n3 == n1 + 1 or n3 == n1 + 2 or n1 == n3 + 1 or (n1 == n3 + 2)))):
	print(1)
else:
	print(2)


s = input().split()
hashi = dict()
for i in s:
	if i in hashi:
		hashi[i] += 1
	else:
		hashi[i] = 1
maxa = 3
for i in ['s', 'm', 'p']:
	for j in range(1, 10):
		z = chr(48 + j) + i
		if z in hashi:
			maxa = min(maxa, 3 - hashi[z])
for i in ['s', 'm', 'p']:
	for j in range(1, 8):
		z1 = chr(48 + j) + i
		z2 = chr(49 + j) + i
		z3 = chr(48 + 2 + j) + i
		count = 0
		if z1 not in hashi:
			count += 1
		if z2 not in hashi:
			count += 1
		if z3 not in hashi:
			count += 1
		maxa = min(count, maxa)
print(maxa)


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def solve():
	s = list(map(str, input().split()))
	m = {}
	m['s'] = []
	m['p'] = []
	m['m'] = []
	for i in s:
		m[i[1]].append(int(i[0]))
	if len(set(s)) == 1:
		print(0)
	elif len(set(s)) == 2:
		print(1)
	elif len(m['s']) == 3:
		p = [m['s'][0], m['s'][1], m['s'][2]]
		p.sort()
		if p[1] - p[0] == 1 and p[2] - p[1] == 1:
			print(0)
		elif p[1] - p[0] == 2 or p[2] - p[1] == 2 or p[1] - p[0] == 1 or (p[2] - p[1] == 1):
			print(1)
		else:
			print(2)
	elif len(m['p']) == 3:
		p = [m['p'][0], m['p'][1], m['p'][2]]
		p.sort()
		if p[1] - p[0] == 1 and p[2] - p[1] == 1:
			print(0)
		elif p[1] - p[0] == 2 or p[2] - p[1] == 2 or p[1] - p[0] == 1 or (p[2] - p[1] == 1):
			print(1)
		else:
			print(2)
	elif len(m['m']) == 3:
		p = [m['m'][0], m['m'][1], m['m'][2]]
		p.sort()
		if p[1] - p[0] == 1 and p[2] - p[1] == 1:
			print(0)
		elif p[1] - p[0] == 2 or p[2] - p[1] == 2 or p[1] - p[0] == 1 or (p[2] - p[1] == 1):
			print(1)
		else:
			print(2)
	elif len(m['s']) == 2 and (abs(m['s'][0] - m['s'][1]) == 1 or abs(m['s'][0] - m['s'][1]) == 2):
		print(1)
	elif len(m['p']) == 2 and (abs(m['p'][0] - m['p'][1]) == 1 or abs(m['p'][0] - m['p'][1]) == 2):
		print(1)
	elif len(m['m']) == 2 and (abs(m['m'][0] - m['m'][1]) == 1 or abs(m['m'][0] - m['m'][1]) == 2):
		print(1)
	else:
		print(2)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


lis = list(map(str, input().split()))
ans = 2
s = len(set(lis))
if s == 1:
	ans = 0
elif s == 2:
	ans = 1
lis.sort()
if int(lis[0][0]) + 1 == int(lis[1][0]) and lis[0][1] == lis[1][1] and (int(lis[1][0]) + 1 == int(lis[2][0])) and (lis[1][1] == lis[2][1]):
	ans = min(ans, 0)
elif int(lis[0][0]) + 1 == int(lis[1][0]) and lis[0][1] == lis[1][1]:
	ans = min(ans, 1)
elif int(lis[1][0]) + 1 == int(lis[2][0]) and lis[1][1] == lis[2][1]:
	ans = min(ans, 1)
elif int(lis[0][0]) + 2 == int(lis[1][0]) and lis[0][1] == lis[1][1]:
	ans = min(ans, 1)
elif int(lis[1][0]) + 2 == int(lis[2][0]) and lis[1][1] == lis[2][1]:
	ans = min(ans, 1)
elif int(lis[0][0]) + 2 == int(lis[2][0]) and lis[0][1] == lis[2][1]:
	ans = min(ans, 1)
elif int(lis[0][0]) + 1 == int(lis[2][0]) and lis[0][1] == lis[2][1]:
	ans = min(ans, 1)
print(ans)


suit = list(map(str, input().split()))
suit = sorted(suit)
num = [int(suit[0][0]), int(suit[1][0]), int(suit[2][0])]
if suit[0] == suit[1] and suit[0] == suit[2]:
	print(0)
elif suit[0] == suit[1] or suit[1] == suit[2]:
	print(1)
elif suit[0][1] == suit[1][1] and suit[0][1] == suit[2][1]:
	if num[0] == num[1] - 1 and num[0] == num[2] - 2:
		print(0)
	elif num[2] - num[1] <= 2 or num[1] - num[0] <= 2:
		print(1)
	else:
		print(2)
elif suit[0][1] == suit[1][1]:
	if num[1] - num[0] <= 2:
		print(1)
	else:
		print(2)
elif suit[0][1] == suit[2][1]:
	if num[2] - num[0] <= 2:
		print(1)
	else:
		print(2)
elif suit[2][1] == suit[1][1]:
	if num[2] - num[1] <= 2:
		print(1)
	else:
		print(2)
else:
	print(2)


li = input().split()
li1 = sorted(map(lambda x: x[0], li))
li2 = sorted(map(lambda x: x[1], li))
if li[0] == li[1] and li[1] == li[2] or (li2[0] == li2[2] and int(max(li1)) - int(min(li1)) == 2 and (li1[0] != li1[1]) and (li1[1] != li1[2])):
	print(0)
elif (li[0] == li[1] or li[0] == li[2] or li[2] == li[1]) or ((abs(int(li[2][0]) - int(li[1][0])) == 2 or abs(int(li[2][0]) - int(li[1][0])) == 1) and li[2][1] == li[1][1]) or ((abs(int(li[2][0]) - int(li[0][0])) == 2 or abs(int(li[2][0]) - int(li[0][0])) == 1) and li[2][1] == li[0][1]) or ((abs(int(li[1][0]) - int(li[0][0])) == 2 or abs(int(li[1][0]) - int(li[0][0])) == 1) and li[1][1] == li[0][1]):
	print(1)
else:
	print(2)


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)
			elif d[s][1] == d[s][2]:
				ans = min(ans, 1)
			elif 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)
			elif d[s][1] + 1 == d[s][2]:
				ans = min(ans, 1)
	if ans == float('inf'):
		print(2)
	else:
		print(ans)
solve()


def main():
	ans = 0
	s = input().split()
	s.sort()
	if s[0] == s[1] and s[1] == s[2]:
		print(ans)
		return
	if s[0][1] == s[1][1] and s[1][1] == s[2][1]:
		if int(s[2][0]) - int(s[1][0]) == 1 and int(s[1][0]) - int(s[0][0]) == 1:
			print(ans)
			return
		else:
			pass
	if s[0] == s[1] or s[1] == s[2] or s[0] == s[2]:
		print(1)
		return
	if s[0][1] == s[1][1] and int(s[1][0]) - int(s[0][0]) < 3 or (s[1][1] == s[2][1] and int(s[2][0]) - int(s[1][0]) < 3) or (s[2][1] == s[0][1] and int(s[2][0]) - int(s[0][0]) < 3):
		print(1)
		return
	print(2)
main()


li = list(input().split(' '))
li.sort()
x = li
ans = 2
if int(x[1][0]) - int(x[0][0]) == 1:
	if x[0][1] == x[1][1]:
		ans = ans - 1
if int(x[1][0]) == int(x[2][0]) - 1:
	if x[1][1] == x[2][1]:
		ans = ans - 1
if int(x[2][0]) - int(x[1][0]) == 2:
	if x[1][1] == x[2][1]:
		ans = min(ans, 1)
if int(x[1][0]) - int(x[0][0]) == 2:
	if x[0][1] == x[1][1]:
		ans = min(ans, 1)
if int(x[2][0]) - int(x[0][0]) == 2:
	if x[0][1] == x[2][1]:
		ans = min(ans, 1)
if int(x[2][0]) - int(x[0][0]) == 1:
	if x[0][1] == x[2][1]:
		ans = min(ans, 1)
m = ans
ans = 2
if int(x[0][0]) == int(x[1][0]):
	if x[0][1] == x[1][1]:
		ans = ans - 1
if int(x[1][0]) == int(x[2][0]):
	if x[1][1] == x[2][1]:
		ans = ans - 1
if int(x[0][0]) == int(x[2][0]):
	if x[0][1] == x[2][1]:
		ans = min(ans, 1)
print(min(ans, m))


(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)


t = input().split(' ')
b = []
for i in range(3):
	b.append(t[i][1])
l2 = len(set(b))
b = list(set(b))
d = {}
for i in range(l2):
	for j in range(3):
		if b[i] == t[j][1]:
			if b[i] not in d:
				d[b[i]] = [int(t[j][0])]
			else:
				d[b[i]].append(int(t[j][0]))
	d[b[i]].sort()
k = 2
m = 2
c = 0
for (key, val) in d.items():
	i = val
	if len(i) == 3:
		if len(set(i)) == 1:
			k = 0
		elif len(set(i)) == 2:
			k = 1
		if i[1] - i[0] == 1 and i[2] - i[1] == 1:
			m = 0
		elif i[1] - i[0] == 1 or i[2] - i[1] == 1 or i[1] - i[0] == 2 or (i[2] - i[1] == 2) or (i[2] - i[0] == 1) or (i[2] - i[0] == 1):
			m = min(m, 1)
	elif len(i) == 2:
		if len(set(i)) == 1:
			k = 1
		elif i[1] - i[0] == 1 or i[1] - i[0] == 2:
			m = min(m, 1)
print(min(k, m))


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))


st = input().split(' ')
nums = sorted([[int(i[0]), i[1]] for i in st])
if st[0] == st[1] and st[1] == st[2]:
	print(0)
elif nums[0][1] == nums[1][1] and nums[1][1] == nums[2][1] and (nums[0][0] == nums[1][0] - 1) and (nums[1][0] == nums[2][0] - 1):
	print(0)
elif nums[0][1] == nums[1][1] and nums[1][0] - nums[0][0] < 3:
	print(1)
elif nums[1][1] == nums[2][1] and nums[2][0] - nums[1][0] < 3:
	print(1)
elif nums[0][1] == nums[2][1] and nums[2][0] - nums[0][0] < 3:
	print(1)
else:
	print(2)


o = input().split()
if o[0] == o[1] == o[2]:
	print(0)
	exit()
pch = int(o[0][0])
vch = int(o[1][0])
tch = int(o[2][0])
l = [pch, vch, tch]
l.sort()
if l[0] + 2 == l[1] + 1 == l[2] and o[0][1] == o[1][1] == o[2][1]:
	print(0)
	exit()
if o[0] == o[1] or o[0] == o[2] or o[1] == o[2]:
	print(1)
	exit()
if pch + 1 == vch and o[0][1] == o[1][1]:
	print(1)
	exit()
if pch + 2 == vch and o[0][1] == o[1][1]:
	print(1)
	exit()
if pch + 1 == tch and o[0][1] == o[2][1]:
	print(1)
	exit()
if pch + 2 == tch and o[0][1] == o[2][1]:
	print(1)
	exit()
if vch + 1 == tch and o[1][1] == o[2][1]:
	print(1)
	exit()
if vch + 2 == tch and o[1][1] == o[2][1]:
	print(1)
	exit()
if pch == vch + 1 and o[0][1] == o[1][1]:
	print(1)
	exit()
if pch == vch + 2 and o[0][1] == o[1][1]:
	print(1)
	exit()
if pch == tch + 1 and o[0][1] == o[2][1]:
	print(1)
	exit()
if pch == tch + 2 and o[0][1] == o[2][1]:
	print(1)
	exit()
if vch == tch + 1 and o[1][1] == o[2][1]:
	print(1)
	exit()
if vch == tch + 2 and o[1][1] == o[2][1]:
	print(1)
	exit()
print(2)


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)))
tiles = read_string_list()
if tiles[0] == tiles[1] == tiles[2]:
	print(0)
	sys.exit()
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()
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()
for k in mps:
	if len(mps[k]) == 2:
		l = mps[k]
		if l[1] - l[0] <= 2:
			print(1)
			sys.exit()
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)
elif 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')
		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)


a = list(input().split())
s = []
m = []
p = []
for i in a:
	if i[1] == 's':
		s.append(int(i[0]))
	elif i[1] == 'm':
		m.append(int(i[0]))
	else:
		p.append(int(i[0]))
if len(s) == 1 and len(m) == 1 and (len(p) == 1):
	print(2)
elif len(s) == 2 or len(m) == 2 or len(p) == 2:
	if len(s) == 2:
		if abs(s[1] - s[0]) < 3:
			print(1)
		else:
			print(2)
	elif len(m) == 2:
		if abs(m[1] - m[0]) < 3:
			print(1)
		else:
			print(2)
	elif abs(p[1] - p[0]) < 3:
		print(1)
	else:
		print(2)
elif len(s) == 3:
	s.sort()
	if s[2] - s[0] == 0:
		print(0)
	elif s[2] - s[1] == 1 and s[1] - s[0] == 1:
		print(0)
	elif s[2] - s[1] < 3 or s[1] - s[0] < 3:
		print(1)
	else:
		print(2)
elif len(m) == 3:
	m.sort()
	if m[2] - m[0] == 0:
		print(0)
	elif m[2] - m[1] == 1 and m[1] - m[0] == 1:
		print(0)
	elif m[2] - m[1] < 3 or m[1] - m[0] < 3:
		print(1)
	else:
		print(2)
else:
	p.sort()
	if p[2] - p[0] == 0:
		print(0)
	elif p[2] - p[1] == 1 and p[1] - p[0] == 1:
		print(0)
	elif p[2] - p[1] < 3 or p[1] - p[0] < 3:
		print(1)
	else:
		print(2)


from sys import *
m = list(input().split())
ans1 = ans2 = 2
d = []
if m[0][1] == m[1][1]:
	if abs(int(m[0][0]) - int(m[1][0])) <= 2 and abs(int(m[0][0]) - int(m[1][0])) != 0:
		ans1 -= 1
		d.append(int(m[0][0]) - int(m[1][0]))
	if abs(int(m[0][0]) - int(m[1][0])) == 0:
		ans2 -= 1
if m[0][1] == m[2][1]:
	if abs(int(m[0][0]) - int(m[2][0])) <= 2 and abs(int(m[0][0]) - int(m[2][0])) != 0:
		if len(d) > 0:
			if abs(int(m[0][0]) - int(m[2][0]) - d[0]) <= 2:
				ans1 -= 1
		else:
			ans1 -= 1
	if abs(int(m[0][0]) - int(m[2][0])) == 0:
		ans2 -= 1
ans = min(ans1, ans2)
if ans <= 1:
	print(ans)
else:
	ans1 = 2
	if m[1][1] == m[2][1]:
		if abs(int(m[1][0]) - int(m[2][0])) <= 2:
			ans1 -= 1
	print(min(ans, ans1))


def check(a, b):
	if a[1] == b[1] and 1 <= abs(int(b[0]) - int(a[0])) <= 2:
		return True
arr = input().split()
d = {}
for i in arr:
	d[i] = d.get(i, 0) + 1
mineq = 3 - max(d.values())
arr.sort(key=lambda x: x[0])
arr.sort(key=lambda x: x[1])
if check(arr[0], arr[1]) or check(arr[1], arr[2]):
	mineq = min(mineq, 1)
if arr[0][1] == arr[1][1] == arr[2][1] and int(arr[2][0]) - int(arr[1][0]) == 1 and (int(arr[1][0]) - int(arr[0][0]) == 1):
	mineq = 0
print(mineq)


tiles = input().split()
l = 0
s = 0
for i in tiles:
	tmp = 0
	for j in tiles:
		if i == j:
			tmp += 1
	l = max(l, tmp)
for i in tiles:
	for j in tiles:
		for k in tiles:
			ans = 1
			if i != j and j != k and (i != k):
				if int(i[0]) == int(j[0]) + 2 and i[1] == j[1]:
					ans += 1
					if int(i[0]) == int(k[0]) + 1 and i[1] == k[1]:
						ans += 1
				elif int(i[0]) == int(j[0]) - 2 and i[1] == j[1]:
					ans += 1
					if int(i[0]) == int(k[0]) - 1 and i[1] == k[1]:
						ans += 1
				elif int(i[0]) == int(j[0]) - 1 and i[1] == j[1] or (int(i[0]) == int(j[0]) + 1 and i[1] == j[1]):
					ans += 1
				elif int(i[0]) == int(k[0]) - 1 and i[1] == k[1] or (int(i[0]) == int(k[0]) + 1 and i[1] == k[1]):
					ans += 1
			s = max(s, ans)
print(min(3 - l, 3 - s))


def f(x: int) -> int:
	return 1 if not not x else 0

def main():
	inp = input().split()
	idx = {'m': 0, 'p': 1, 's': 2}
	table = [[0] * 9 for _ in range(3)]
	for i in inp:
		r = idx[i[1]]
		c = int(i[0]) - 1
		table[r][c] += 1
	ans = 3
	for i in range(3):
		for j in range(9):
			ans = min(ans, 3 - table[i][j])
			if j + 2 < 9:
				ans = min(ans, 3 - f(table[i][j]) - f(table[i][j + 1]) - f(table[i][j + 2]))
	print(ans)
main()


def main():
	buf = input()
	buflist = buf.split()
	hand = buflist
	t = []
	for i in range(3):
		t.append([])
		for j in range(9):
			t[i].append(0)
	for x in hand:
		idx = 0
		if x[1] == 'm':
			idx = 0
		elif x[1] == 'p':
			idx = 1
		elif x[1] == 's':
			idx = 2
		t[idx][int(x[0]) - 1] += 1
	max_cons = 0
	max_mult = 0
	for i in range(3):
		cons = [0, 0, 0]
		for j in range(9):
			cons[0] = cons[1]
			cons[1] = cons[2]
			if t[i][j] > 0:
				cons[2] = 1
			else:
				cons[2] = 0
			max_cons = max(sum(cons), max_cons)
			max_mult = max(max_mult, t[i][j])
	print(3 - max(max_cons, max_mult))

def __starting_point():
	main()
__starting_point()


hand = input().split()
s_hand = [[] for i in range(3)]
shuntsu = 100
for i in hand:
	s_hand['mps'.index(i[1])].append(int(i[0]))
for i in s_hand:
	if not i:
		continue
	if len(i) == 1:
		shuntsu = min(shuntsu, 2)
	elif len(i) == 2:
		shuntsu = min(shuntsu, 1 if abs(i[0] - i[1]) in (1, 2) else 100)
	else:
		s_i = sorted(i)
		if s_i[0] + 1 == s_i[1] and s_i[1] + 1 == s_i[2]:
			shuntsu = 0
		else:
			shuntsu = min(shuntsu, min(1 if abs(i[0] - i[1]) in (1, 2) else 100, 1 if abs(i[1] - i[2]) in (1, 2) else 100, 1 if abs(i[0] - i[2]) in (1, 2) else 100))
t = len(set(hand))
koutsu = 0 if t == 1 else 1 if t == 2 else 2
print(min(shuntsu, koutsu))


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


GI = lambda : int(input())
GIS = lambda : map(int, input().split())
LGIS = lambda : list(GIS())

def main():
	cards = input().strip().split()
	d = {c: [0] * 9 for c in 'smp'}
	for card in cards:
		(num, suite) = (card[0], card[1])
		num = int(num)
		d[suite][num - 1] += 1
	mn = float('inf')
	for l in d.values():
		for (i, x) in enumerate(l):
			mn = min(mn, 3 - max(x, sum(map(bool, l[i:i + 3]))))
	print(max(mn, 0))
main()


(t1, t2, t3) = map(str, input().split(' '))
arr = sorted([int(t1[0]), int(t2[0]), int(t3[0])])
if t1 == t2 and t2 == t3 or (t1[1] == t2[1] and t2[1] == t3[1] and (arr[2] - arr[1] == 1) and (arr[1] - arr[0] == 1)):
	print(0)
elif t1 == t2 or t2 == t3 or t3 == t1:
	print(1)
elif t1[1] == t2[1] and (abs(int(t1[0]) - int(t2[0])) == 1 or abs(int(t1[0]) - int(t2[0])) == 2):
	print(1)
elif t2[1] == t3[1] and (abs(int(t3[0]) - int(t2[0])) == 1 or abs(int(t3[0]) - int(t2[0])) == 2):
	print(1)
elif t1[1] == t3[1] and (abs(int(t1[0]) - int(t3[0])) == 1 or abs(int(t1[0]) - int(t3[0])) == 2):
	print(1)
else:
	print(2)


q = list(input().split())
s1 = q[0]
s2 = q[1]
s3 = q[2]
l = []
l.append(int(s1[:-1]))
l.append(int(s2[:-1]))
l.append(int(s3[:-1]))
if s1 == s2 == s3:
	print('0')
	exit()
if s1[-1] == s2[-1] and s2[-1] == s3[-1] and (s3[-1] == s1[-1]):
	a = sorted(l)
	if a[2] - a[0] == 2 and a[1] - a[0] == 1:
		print('0')
		exit()
if s1 == s2 or s2 == s3 or s1 == s3:
	print('1')
	exit()
if s1[-1] != s2[-1] and s2[-1] != s3[-1] and (s3[-1] != s1[-1]):
	print(2)
	exit()
if s1[-1] == s2[-1]:
	if abs(int(s1[:-1]) - int(s2[:-1])) == 2 or abs(int(s1[:-1]) - int(s2[:-1])) == 1:
		print(1)
		exit()
if s1[-1] == s3[-1]:
	if abs(int(s1[:-1]) - int(s3[:-1])) == 2 or abs(int(s1[:-1]) - int(s3[:-1])) == 1:
		print(1)
		exit()
if s2[-1] == s3[-1]:
	if abs(int(s2[:-1]) - int(s3[:-1])) == 2 or abs(int(s2[:-1]) - int(s3[:-1])) == 1:
		print(1)
		exit()
print(2)


tup = lambda s: (int(s[0]), s[1])
mlist = []
plist = []
slist = []
ilist = input().split()
for i in ilist:
	if i[1] == 'm':
		mlist.append(int(i[0]))
	if i[1] == 'p':
		plist.append(int(i[0]))
	if i[1] == 's':
		slist.append(int(i[0]))
mlist.sort()
plist.sort()
slist.sort()
mdiff = []
pdiff = []
sdiff = []
for i in range(len(mlist) - 1):
	mdiff.append(mlist[i + 1] - mlist[i])
for i in range(len(plist) - 1):
	pdiff.append(plist[i + 1] - plist[i])
for i in range(len(slist) - 1):
	sdiff.append(slist[i + 1] - slist[i])
mi0 = False
mi1 = False
mi2 = False
consec0 = False
consec1 = False
for i in range(len(mdiff)):
	if mdiff[i] == 0:
		if (not isinstance(mi0, bool)) & (mi0 == i - 1):
			consec0 = True
			break
		mi0 = i
	if mdiff[i] == 1:
		if (not isinstance(mi1, bool)) & (mi1 == i - 1):
			consec1 = True
			break
		mi1 = i
	if mdiff[i] == 2:
		mi2 = i
pi0 = False
pi1 = False
pi2 = False
for i in range(len(pdiff)):
	if pdiff[i] == 0:
		if (not isinstance(pi0, bool)) & (pi0 == i - 1):
			consec0 = True
			break
		pi0 = i
	if pdiff[i] == 1:
		if (not isinstance(pi1, bool)) & (pi1 == i - 1):
			consec1 = True
			break
		pi1 = i
	if pdiff[i] == 2:
		pi2 = i
si0 = False
si1 = False
si2 = False
for i in range(len(sdiff)):
	if sdiff[i] == 0:
		if (not isinstance(si0, bool)) & (si0 == i - 1):
			consec0 = True
			break
		si0 = i
	if sdiff[i] == 1:
		if (not isinstance(si1, bool)) & (si1 == i - 1):
			consec1 = True
			break
		si1 = i
	if sdiff[i] == 2:
		si2 = i
if consec0:
	print(0)
elif not isinstance(mi0, bool):
	print(1)
elif not isinstance(pi0, bool):
	print(1)
elif not isinstance(si0, bool):
	print(1)
elif consec1:
	print(0)
elif not isinstance(mi1, bool):
	print(1)
elif not isinstance(pi1, bool):
	print(1)
elif not isinstance(si1, bool):
	print(1)
elif not isinstance(mi2, bool):
	print(1)
elif not isinstance(pi2, bool):
	print(1)
elif not isinstance(si2, bool):
	print(1)
else:
	print(2)


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)
a = input()
tmp = a.split(' ')
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])
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))


a = input().split()
a.sort()
if a[0] == a[1] == a[2]:
	print(0)
elif int(a[0][0]) + 1 == int(a[1][0]) == int(a[2][0]) - 1 and a[0][1] == a[1][1] == a[2][1]:
	print(0)
elif a[0] == a[1] or a[0] == a[2] or a[1] == a[2]:
	print(1)
elif int(a[0][0]) + 1 == int(a[1][0]) and a[0][1] == a[1][1] or (int(a[0][0]) + 1 == int(a[2][0]) and a[0][1] == a[2][1]) or (int(a[1][0]) + 1 == int(a[2][0]) and a[1][1] == a[2][1]):
	print(1)
elif int(a[0][0]) + 2 == int(a[1][0]) and a[0][1] == a[1][1] or (int(a[0][0]) + 2 == int(a[2][0]) and a[0][1] == a[2][1]) or (int(a[1][0]) + 2 == int(a[2][0]) and a[1][1] == a[2][1]):
	print(1)
else:
	print(2)


while True:
	try:
		(a, b, c) = map(str, input().split())
		lis = a + b + c
		teli = [a, b, c]
		teli.sort()
		d1 = int(teli[1][0]) - int(teli[0][0])
		d2 = int(teli[2][0]) - int(teli[1][0])
		d3 = int(teli[2][0]) - int(teli[0][0])
		(flag, end) = (False, False)
		if d1 == 0 and d2 == 0 or (d1 == 1 and d2 == 1):
			flag = True
		if flag:
			if lis.count(lis[1]) == 3:
				print('0')
				continue
		if d1 == 0 or d1 == 1 or d1 == 2:
			if teli[0][1] == teli[1][1]:
				print('1')
				continue
		if d2 == 1 or d2 == 0 or d2 == 2:
			if teli[1][1] == teli[2][1]:
				print('1')
				continue
		if d3 == 0 or d3 == 1 or d3 == 2:
			if teli[0][1] == teli[2][1]:
				print('1')
				continue
		print('2')
	except EOFError:
		break


from collections import Counter as ct
a = map(lambda x: (int(x[0]), x[1]), input().split())
ms = {'s': [], 'p': [], 'm': []}
for (num, suit) in a:
	ms[suit].append(num)

def to_koutsu(arr: list):
	st = ct(arr).most_common()
	return 3 - st[0][1]

def to_shuntsu(arr: list):
	st = list(sorted(arr))
	step = 0
	for (x, y) in zip(st[:-1], st[1:]):
		if y - x == 1:
			step += 1
		if y - x == 2:
			return 1
	return 3 - (step + 1)
minNum = 3
for tile in ms.values():
	if not tile:
		continue
	elif len(tile) == 1:
		minNum = min(minNum, 2)
	else:
		minNum = min(minNum, min(to_koutsu(tile), to_shuntsu(tile)))
print(minNum)


arr = [i for i in input().split()]
mem = sorted([[int(i[0]), i[1]] for i in arr])
if len(set(arr)) == 1 or (arr[0][1] == arr[1][1] == arr[2][1] and mem[0][0] == mem[1][0] - 1 == mem[2][0] - 2):
	print(0)
elif 1 <= mem[1][0] - mem[0][0] <= 2 and mem[1][1] == mem[0][1] or (1 <= mem[2][0] - mem[1][0] <= 2 and mem[2][1] == mem[1][1]) or (1 <= mem[2][0] - mem[0][0] <= 2 and mem[2][1] == mem[0][1]):
	print(1)
elif len(set(arr)) == 2:
	print(1)
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]
best.sort()
if len(best) == 1:
	print(2)
elif len(set(best)) == 1:
	print(3 - len(best))
elif len(best) == 3:
	if best[0] == best[1] - 1 and best[2] == best[1] + 1:
		print(0)
	elif best[0] + 1 == best[1] or best[1] + 1 == best[2]:
		print(1)
	elif best[0] == best[1] or best[1] == best[2]:
		print(1)
	elif best[0] + 2 == best[1] or best[1] + 2 == best[2]:
		print(1)
	else:
		print(2)
elif len(best) == 2:
	if best[0] == best[1]:
		print(1)
	elif best[0] == best[1] - 1:
		print(1)
	elif best[0] + 2 == best[1]:
		print(1)
	else:
		print(2)
else:
	print(2)


input = input().split()
if input.count(input[0]) == 3:
	print(0)
elif input.count(input[0]) == 2:
	print(1)
elif input.count(input[1]) == 2:
	print(1)
elif input.count(input[2]) == 2:
	print(1)
else:
	num_0 = [int(i) for i in input[0] if i in '123456789']
	num_1 = [int(i) for i in input[1] if i in '123456789']
	num_2 = [int(i) for i in input[2] if i in '123456789']
	char_0 = [i for i in input[0] if i not in '123456789']
	char_1 = [i for i in input[1] if i not in '123456789']
	char_2 = [i for i in input[2] if i not in '123456789']
	num = []
	num.extend(num_0)
	num.extend(num_1)
	num.extend(num_2)
	num.sort()
	if char_0 == char_2 and char_2 == char_1 and (num[0] + 1 == num[1]) and (num[1] + 1 == num[2]):
		print(0)
	elif abs(num_0[0] - num_1[0]) < 3 and char_0 == char_1:
		print(1)
	elif abs(num_1[0] - num_2[0]) < 3 and char_1 == char_2:
		print(1)
	elif abs(num_2[0] - num_0[0]) < 3 and char_2 == char_0:
		print(1)
	else:
		print(2)


s = list(input().split())
M = []
P = []
S = []
for i in s:
	if i[1] == 'm':
		M.append(int(i[0]))
	elif i[1] == 's':
		S.append(int(i[0]))
	elif i[1] == 'p':
		P.append(int(i[0]))
x = True
for i in [M, P, S]:
	if len(i) == 3:
		i.sort()
		if i[0] == i[1] and i[1] == i[2] or (i[0] + 1 == i[1] and i[1] + 1 == i[2]):
			x = False
			print(0)
if x:
	for i in [M, P, S]:
		if len(i) == 3:
			i.sort()
			if (i[0] == i[1] or i[1] == i[2]) or (i[0] + 1 == i[1] or i[1] + 1 == i[2]) or i[0] + 2 == i[1] or (i[1] + 2 == i[2]):
				x = False
				print(1)
		elif len(i) == 2:
			i.sort()
			if i[0] + 1 == i[1] or i[0] == i[1] or i[0] + 2 == i[1]:
				x = False
				print(1)
if x:
	print(2)


import itertools

def cmp(A, B):
	cnt = 0
	for i in range(3):
		cnt += A[i] != B[i]
	return cnt
a = '123456789'
b = 'mps'
x = map(str, input().split())
x = sorted(list(x))
A = []
for i in range(len(a) - 2):
	for j in range(len(b)):
		B = [a[i] + b[j], a[i + 1] + b[j], a[i + 2] + b[j]]
		A.append(B)
for i in range(len(a)):
	for j in range(len(b)):
		B = [a[i] + b[j], a[i] + b[j], a[i] + b[j]]
		A.append(B)
mn = 10
for lst in A:
	for ls in itertools.permutations(x):
		mn = min(mn, cmp(lst, ls))
print(mn)


def main():
	cards = input().split()
	my_list = []
	if cards[0] == cards[1] == cards[2]:
		ans = 0
		print(ans)
	elif cards[0][1] == cards[1][1] == cards[2][1]:
		first_number = int(cards[0][0])
		Secound_number = int(cards[1][0])
		third_nubmer = int(cards[2][0])
		difference = first_number - Secound_number
		difference1 = first_number - third_nubmer
		difference2 = Secound_number - third_nubmer
		for i in range(0, 3):
			my_list.append(int(cards[i][0]))
		my_list.sort()
		if int(my_list[1]) - int(my_list[0]) == 1 and int(my_list[2]) - int(my_list[1]) == 1:
			ans = 0
			print(ans)
		elif difference == 1 or difference == -1 or difference == 0 or (difference == 2) or (difference == -2) or (difference1 == 1) or (difference1 == -1) or (difference1 == 0) or (difference1 == 2) or (difference1 == -2) or (difference2 == 1) or (difference2 == -1) or (difference2 == 0) or (difference2 == 2) or (difference2 == -2):
			ans = 1
			print(ans)
		else:
			ans = 2
			print(ans)
	elif cards[0][1] != cards[1][1] and cards[0][1] != cards[2][1] and (cards[1][1] != cards[2][1]):
		ans = 2
		print(ans)
	elif cards[0][1] == cards[1][1] or cards[0][1] == cards[2][1] or cards[1][1] == cards[2][1]:
		if cards[0][1] == cards[1][1]:
			first_number = int(cards[0][0])
			Secound_number = int(cards[1][0])
			difference = first_number - Secound_number
			if difference == 1 or difference == -1 or difference == 0 or (difference == 2) or (difference == -2):
				ans = 1
				print(ans)
			else:
				ans = 2
				print(ans)
		elif cards[0][1] == cards[2][1]:
			first_number = int(cards[0][0])
			Secound_number = int(cards[2][0])
			difference = first_number - Secound_number
			if difference == 1 or difference == -1 or difference == 0 or (difference == 2) or (difference == -2):
				ans = 1
				print(ans)
			else:
				ans = 2
				print(ans)
		elif cards[1][1] == cards[2][1]:
			first_number = int(cards[2][0])
			Secound_number = int(cards[1][0])
			difference = first_number - Secound_number
			if difference == 1 or difference == -1 or difference == 0 or (difference == 2) or (difference == -2):
				ans = 1
				print(ans)
			else:
				ans = 2
				print(ans)
main()


import math
import sys
import collections

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))
d = sorted(input().split())
n = sorted([int(x[0]) for x in d])
m = sorted([x[1] for x in d])
dic = {'s': [], 'p': [], 'm': []}
for i in d:
	dic[i[1]].append(int(i[0]))
nr = 1
for i in dic:
	if len(dic[i]) == 2:
		if 0 < dic[i][1] - dic[i][0] <= 2:
			nr = 2
	if len(dic[i]) == 3:
		if dic[i][1] - dic[i][0] == dic[i][2] - dic[i][1] == 1:
			nr = 3
			break
		if 0 < dic[i][1] - dic[i][0] <= 2:
			nr = 2
		if 0 < dic[i][2] - dic[i][1] <= 2:
			nr = 2
		if 0 < dic[i][2] - dic[i][0] <= 2:
			nr = 2
mr = 1
for i in range(1, 3):
	if d[i] == d[i - 1]:
		mr += 1
print(min(3 - mr, 3 - nr))


s = input().split()
s.sort()
if s[0] == s[2] or (s[0] == s[1] and s[0] == s[2]):
	print(0)
	exit()
d = [int(i[0]) for i in s]
c = [ord(i[1]) for i in s]
if d[1] == d[0] + 1 and d[2] == d[0] + 2 and (c[0] == c[1]) and (c[0] == c[2]):
	print(0)
	exit()
dem = {i for i in s}
ans = len(dem) - 1
for i in range(3):
	for j in range(3):
		if i == j:
			continue
		if (abs(d[i] - d[j]) == 1 or abs(d[i] - d[j]) == 2) and c[i] == c[j]:
			ans = 1
			break
print(ans)


import collections
a = input().split()
a.sort()
if a[0] == a[1] and a[1] == a[2]:
	print(0)
elif a[0][1] == a[1][1] and a[1][1] == a[2][1] and (abs(int(a[1][0]) - int(a[0][0])) == 1) and (abs(int(a[2][0]) - int(a[1][0])) == 1):
	print('0')
elif a[0] == a[1] or a[1] == a[2] or a[2] == a[0]:
	print('1')
elif a[0][1] == a[1][1] and (abs(int(a[1][0]) - int(a[0][0])) == 1 or abs(int(a[1][0]) - int(a[0][0])) == 2):
	print('1')
elif a[1][1] == a[2][1] and (abs(int(a[2][0]) - int(a[1][0])) == 1 or abs(int(a[2][0]) - int(a[1][0])) == 2):
	print('1')
elif a[0][1] == a[2][1] and (abs(int(a[2][0]) - int(a[0][0])) == 1 or abs(int(a[2][0]) - int(a[0][0])) == 2):
	print('1')
else:
	print('2')


(a, b, c) = tuple([x for x in input().split()])
(m, p, s) = ([], [], [])
if a[1] == 'm':
	m.append(int(a[0]))
elif a[1] == 'p':
	p.append(int(a[0]))
elif a[1] == 's':
	s.append(int(a[0]))
if b[1] == 'm':
	m.append(int(b[0]))
elif b[1] == 'p':
	p.append(int(b[0]))
elif b[1] == 's':
	s.append(int(b[0]))
if c[1] == 'm':
	m.append(int(c[0]))
elif c[1] == 'p':
	p.append(int(c[0]))
elif c[1] == 's':
	s.append(int(c[0]))
m.sort()
p.sort()
s.sort()
ans = 0
if len(m) == 1 and len(p) == 1 and (len(s) == 1):
	ans = 2
elif len(m) == 2:
	if m[0] - m[1] in [-2, -1, 0]:
		ans = 1
	else:
		ans = 2
elif len(p) == 2:
	if p[0] - p[1] in [-2, -1, 0]:
		ans = 1
	else:
		ans = 2
elif len(s) == 2:
	if s[0] - s[1] in [-2, -1, 0]:
		ans = 1
	else:
		ans = 2
elif len(m) == 3:
	if m[0] - m[1] == -1 and m[1] - m[2] == -1 or (m[0] - m[1] == 0 and m[1] - m[2] == 0):
		ans = 0
	elif (m[0] - m[1] == 0 or m[1] - m[2] == 0) or (m[0] - m[1] == -1 or m[1] - m[2] == -1) or (m[0] - m[1] == -2 or m[1] - m[2] == -2):
		ans = 1
	else:
		ans = 2
elif len(p) == 3:
	if p[0] - p[1] == -1 and p[1] - p[2] == -1 or (p[0] - p[1] == 0 and p[1] - p[2] == 0):
		ans = 0
	elif (p[0] - p[1] == 0 or p[1] - p[2] == 0) or (p[0] - p[1] == -1 or p[1] - p[2] == -1) or (p[0] - p[1] == -2 or p[1] - p[2] == -2):
		ans = 1
	else:
		ans = 2
elif len(s) == 3:
	if s[0] - s[1] == -1 and s[1] - s[2] == -1 or (s[0] - s[1] == 0 and s[1] - s[2] == 0):
		ans = 0
	elif (s[0] - s[1] == 0 or s[1] - s[2] == 0) or (s[0] - s[1] == -1 or s[1] - s[2] == -1) or (s[0] - s[1] == -2 or s[1] - s[2] == -2):
		ans = 1
	else:
		ans = 2
print(ans)


(x, y, z) = input().split()
v = list((x, y, z))
v.sort()
a = int(v[0][0])
b = int(v[1][0])
c = int(v[2][0])
l = v[0][1]
m = v[1][1]
n = v[2][1]
if x == y and y == z:
	print(0)
elif x == y and y != z or (x == z and y != z) or (y == z and x != z):
	print(1)
elif l == m and m == n:
	if b == a + 1 and c == b + 1:
		print(0)
	elif b == a + 1 and c != b + 1 or (c == b + 1 and b != a + 1):
		print(1)
	elif b == a + 2 or c == b + 2:
		print(1)
	else:
		print(2)
elif l == m and m != n:
	if b == a + 1 or b == a + 2 or b == a:
		print(1)
	else:
		print(2)
elif m == n and l != n:
	if c == b + 1 or c == b or c == b + 2:
		print(1)
	else:
		print(2)
elif l == n and n != m:
	if c == a + 1 or c == a or c == a + 2:
		print(1)
	else:
		print(2)
else:
	print(2)


c = list(input().split())
a = []
for i in range(3):
	a.append([])
for n in c:
	if n[1] == 'p':
		a[0].append(int(n[0]))
	elif n[1] == 'm':
		a[1].append(int(n[0]))
	else:
		a[2].append(int(n[0]))
m = 2
for i in range(3):
	a[i].sort()
	if len(a[i]) == 3 and a[i][0] == a[i][1] and (a[i][1] == a[i][2]):
		m = 0
	if len(a[i]) == 3 and a[i][1] - a[i][0] == 1 and (a[i][2] - a[i][1] == 1):
		m = 0
	if len(a[i]) == 3 and (a[i][1] - a[i][0] <= 2 or a[i][2] - a[i][1] <= 2):
		m = min(m, 1)
	if len(a[i]) == 2 and a[i][1] - a[i][0] in [0, 1, 2]:
		m = min(m, 1)
if c[0] == c[1] and c[1] == c[2]:
	m = 0
print(m)


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():
	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]:
		nums = sorted([int(m[0]) for m in mark])
		if len(mark) <= 1:
			pass
		elif len(mark) == 2:
			if mark[0] == mark[1]:
				ans = 1
			if nums[1] - nums[0] <= 2:
				ans = 1
		else:
			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)
main()


s = input().split()
b = []
b.append((s[0][1], int(s[0][0])))
b.append((s[1][1], int(s[1][0])))
b.append((s[2][1], int(s[2][0])))
b.sort()
if b[0][0] == b[1][0] and b[1][0] == b[2][0]:
	if b[0] == b[1] and b[1] == b[2]:
		print(0)
	elif b[0][1] + 1 == b[1][1] and b[1][1] + 1 == b[2][1]:
		print(0)
	elif b[0] == b[1]:
		print(1)
	elif b[1] == b[2]:
		print(1)
	elif b[0][1] + 1 == b[1][1]:
		print(1)
	elif b[0][1] + 2 == b[1][1]:
		print(1)
	elif b[1][1] + 1 == b[2][1]:
		print(1)
	elif b[1][1] + 2 == b[2][1]:
		print(1)
	elif b[0][1] + 1 == b[2][1]:
		print(1)
	elif b[0][1] + 2 == b[2][1]:
		print(1)
	else:
		print(2)
elif b[0][0] != b[1][0] and b[1][0] != b[2][0] and (b[2][0] != b[0][0]):
	print(2)
elif b[0][0] == b[1][0]:
	if b[0] == b[1]:
		print(1)
	elif b[0][1] + 1 == b[1][1]:
		print(1)
	elif b[0][1] + 2 == b[1][1]:
		print(1)
	else:
		print(2)
elif b[1][0] == b[2][0]:
	if b[1] == b[2]:
		print(1)
	elif b[1][1] + 1 == b[2][1]:
		print(1)
	elif b[1][1] + 2 == b[2][1]:
		print(1)
	else:
		print(2)
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)


s = list(input().split())
s.sort()
if s[0] == s[2]:
	print(0)
	exit()
elif int(s[0][0]) + 2 == int(s[1][0]) + 1 == int(s[2][0]) and s[0][1] == s[1][1] == s[2][1]:
	print(0)
	exit()
elif s[0][1] == s[1][1] and int(s[1][0]) - int(s[0][0]) <= 2:
	print(1)
elif s[1][1] == s[2][1] and int(s[2][0]) - int(s[1][0]) <= 2:
	print(1)
elif s[2][1] == s[0][1] and int(s[2][0]) - int(s[0][0]) <= 2:
	print(1)
else:
	print(2)


def main():
	(a, b, c) = input().split()
	nums = sorted(list(map(int, [a[0], b[0], c[0]])))
	chars = [a[1], b[1], c[1]]
	tup = sorted(list(map(lambda x: (int(x[0]), x[1]), [a, b, c])), key=lambda x: x[0])
	if a == b and b == c:
		return 0
	if nums[0] + 1 == nums[1] and nums[1] + 1 == nums[2] and (len(set(chars)) == 1):
		return 0
	if a == b or b == c or c == a:
		return 1
	if len(set(chars)) <= 2:
		if tup[0][1] == tup[1][1]:
			if tup[0][0] + 1 == tup[1][0] or tup[0][0] + 2 == tup[1][0]:
				return 1
		if tup[0][1] == tup[2][1]:
			if tup[0][0] + 1 == tup[2][0] or tup[0][0] + 2 == tup[2][0]:
				return 1
		if tup[1][1] == tup[2][1]:
			if tup[1][0] + 1 == tup[2][0] or tup[1][0] + 2 == tup[2][0]:
				return 1
	return 2
print(main())


a = input().split()
ans = 2
for i in range(1, 10):
	for c in 'spm':
		ans = min(ans, max(0, 3 - a.count(str(i) + c)))
		ans = min(ans, (not str(i - 1) + c in a) + (not str(i) + c in a) + (not str(i + 1) + c in a))
print(ans)


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)
		elif max(sp) - min(sp) == 2:
			print(0)
		elif sp[1] - sp[0] < 3:
			print(1)
		elif sp[2] - sp[1] < 3:
			print(1)
		else:
			print(2)
		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)


l = list(input().split())
for i in range(3):
	l[i] = [l[i][1], l[i][0]]
l.sort()
for i in range(3):
	l[i] = [l[i][1], l[i][0]]
flag = 0
if l[0] == l[1]:
	if l[1] == l[2]:
		print(0)
	else:
		print(1)
elif l[1] == l[2]:
	print(1)
elif l[0][1] == l[1][1]:
	if abs(int(l[1][0]) - int(l[0][0])) == 1:
		if l[2][1] == l[1][1]:
			if abs(int(l[2][0]) - int(l[1][0])) == 1:
				print(0)
			else:
				print(1)
		else:
			print(1)
	elif abs(int(l[1][0]) - int(l[0][0])) == 2:
		print(1)
	else:
		flag = 1
else:
	flag = 1
if flag == 1:
	if l[1][1] == l[2][1]:
		if abs(int(l[2][0]) - int(l[1][0])) <= 2:
			print(1)
		else:
			print(2)
	else:
		print(2)


hand = input().split()
(m, p, s) = (9 * [False], 9 * [False], 9 * [False])
for h in hand:
	if h[1] == 'm':
		m[int(h[0]) - 1] = True
	if h[1] == 'p':
		p[int(h[0]) - 1] = True
	if h[1] == 's':
		s[int(h[0]) - 1] = True
if hand[0] == hand[1] and hand[0] == hand[2]:
	print(0)
	quit()
for i in range(9):
	if i > 0 and i + 1 < 9:
		if m[i - 1] and m[i] and m[i + 1]:
			print(0)
			quit()
		if p[i - 1] and p[i] and p[i + 1]:
			print(0)
			quit()
		if s[i - 1] and s[i] and s[i + 1]:
			print(0)
			quit()
if hand[0] == hand[1] or hand[0] == hand[2] or hand[1] == hand[2]:
	print(1)
	quit()
for i in range(1, 8):
	cnt = 0
	cnt += 1 if m[i - 1] else 0
	cnt += 1 if m[i + 0] else 0
	cnt += 1 if m[i + 1] else 0
	if cnt == 2:
		print(1)
		quit()
	cnt = 0
	cnt += 1 if p[i - 1] else 0
	cnt += 1 if p[i + 0] else 0
	cnt += 1 if p[i + 1] else 0
	if cnt == 2:
		print(1)
		quit()
	cnt = 0
	cnt += 1 if s[i - 1] else 0
	cnt += 1 if s[i + 0] else 0
	cnt += 1 if s[i + 1] else 0
	if cnt == 2:
		print(1)
		quit()
print(2)
quit()


A = input().split(' ')
s = [0] * 10
p = [0] * 10
m = [0] * 10
for item in A:
	inte = int(item[0])
	if item[1] == 's':
		s[inte] += 1
	elif item[1] == 'p':
		p[inte] += 1
	elif item[1] == 'm':
		m[inte] += 1
req = 3
ans = 3
for i in range(1, 10):
	req = 3 - s[i]
	if req < ans:
		ans = req
	req = 3 - p[i]
	if req < ans:
		ans = req
	req = 3 - m[i]
	if req < ans:
		ans = req
for j in range(1, 8):
	sm = 0
	for k in range(j, j + 3):
		if not s[k] == 0:
			sm += 1
	req = 3 - sm
	if req < ans:
		ans = req
	sm = 0
	for k in range(j, j + 3):
		if not m[k] == 0:
			sm += 1
	req = 3 - sm
	if req < ans:
		ans = req
	sm = 0
	for k in range(j, j + 3):
		if not p[k] == 0:
			sm += 1
	req = 3 - sm
	if req < ans:
		ans = req
print(ans)


from sys import setcheckinterval, stdin
setcheckinterval(1000)
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)


string = input().split()
first = string[0]
second = string[1]
third = string[2]
string.sort(key=lambda x: int(x[0]))
if first == second == third or (first[1] == second[1] == third[1] and all((int(string[i][0]) == int(string[i - 1][0]) + 1 for i in range(1, 3)))):
	print(0)
elif first == second or second == third or third == first or (string[0][1] == string[1][1] and int(string[1][0]) - int(string[0][0]) <= 2) or (string[1][1] == string[2][1] and int(string[2][0]) - int(string[1][0]) <= 2) or (string[0][1] == string[2][1] and int(string[2][0]) - int(string[0][0]) <= 2):
	print(1)
else:
	print(2)


a = input().split()
a.sort()
b = [int(a[0][0]), int(a[1][0]), int(a[2][0])]
e = [a[0][1], a[1][1], a[2][1]]
if len(set(a)) == 1:
	print(0)
elif a[0] == a[1] or a[1] == a[2]:
	print(1)
elif len(set(e)) == 3:
	print(2)
elif len(set(e)) == 1:
	b.sort()
	k = 2
	o = 0
	if b[1] - b[0] == 1:
		k -= 1
		o = 1
	if b[2] - b[1] == 1:
		k -= 1
		o = 1
	if o == 0 and (b[1] - b[0] != 1 and b[1] - b[0] == 2 or (b[1] - b[0] == 2 and b[1] - b[0] != 1) or (b[1] - b[0] == 2 and b[1] - b[0] == 2)):
		k -= 1
	print(k)
elif e[0] == e[1]:
	if abs(b[0] - b[1]) == 1 or abs(b[0] - b[1]) == 2:
		print(1)
	else:
		print(2)
elif e[1] == e[2]:
	if abs(b[1] - b[2]) == 1 or abs(b[1] - b[2]) == 2:
		print(1)
	else:
		print(2)
elif e[0] == e[2]:
	if abs(b[0] - b[2]) == 1 or abs(b[0] - b[2]) == 2:
		print(1)
	else:
		print(2)


s = input()
st = s.split()
st.sort()
ans = 2
if st[0] == st[1] and st[1] == st[2]:
	ans = 0
if st[0][1] == st[1][1] and st[1][1] == st[2][1]:
	if int(st[0][0]) + 1 == int(st[1][0]) and int(st[1][0]) + 1 == int(st[2][0]):
		ans = 0
if st[0] == st[1] or st[1] == st[2] or st[0] == st[2]:
	ans = min(1, ans)
if st[0][1] == st[1][1]:
	if int(st[1][0]) - int(st[0][0]) <= 2:
		ans = min(1, ans)
if st[0][1] == st[2][1]:
	if int(st[2][0]) - int(st[0][0]) <= 2:
		ans = min(1, ans)
if st[1][1] == st[2][1]:
	if int(st[2][0]) - int(st[1][0]) <= 2:
		ans = min(1, ans)
print(str(ans))


def vsort(a):
	s = []
	m = []
	p = []
	for i in range(3):
		k = a[i]
		if k[1] == 's':
			s.append(k)
		elif k[1] == 'p':
			p.append(k)
		else:
			m.append(k)
	s.sort()
	m.sort()
	p.sort()
	v = []
	for i in m:
		v.append(i)
	for i in p:
		v.append(i)
	for i in s:
		v.append(i)
	return v

def next(a, b):
	a1 = int(a[0])
	b1 = int(b[0])
	a2 = a[1]
	b2 = b[1]
	if a1 == b1 + 1 and a2 == b2:
		return 1
	elif a1 == b1 + 2 and a2 == b2:
		return 2
	else:
		return 0

def count(i):
	ans = 2
	if a[i + 1] == a[i]:
		ans = 1
		if i + 2 < len(a) and a[i + 2] == a[i]:
			ans = 0
	elif next(a[i + 1], a[i]) == 1:
		ans -= 1
		if i + 2 < len(a) and next(a[i + 2], a[i + 1]) == 1:
			ans -= 1
	elif next(a[i + 1], a[i]) == 2:
		ans -= 1
	return ans
a = [i for i in input().split()]
a = vsort(a)
min = 2
for i in range(2):
	if count(i) < min:
		min = count(i)
print(min)


import sys
import math
from collections import defaultdict, deque
input = sys.stdin.readline

def inar():
	return [int(el) for el in input().split()]

def main():
	(a, b, c) = input().split()
	if a[1] == b[1] == c[1]:
		lol = [int(a[0]), int(b[0]), int(c[0])]
		lol.sort()
		if lol[0] + 1 == lol[1] and lol[1] + 1 == lol[2] or a[0] == b[0] == c[0]:
			print(0)
		elif (lol[0] + 1 == lol[1] or lol[1] + 1 == lol[2]) or (lol[0] == lol[1] or lol[1] == lol[2]) or lol[0] + 2 == lol[1] or (lol[1] + 2 == lol[2]):
			print(1)
		else:
			print(2)
	else:
		lol = [a[1], b[1], c[1]]
		lol.sort()
		char = ''
		if lol[0] == lol[1] or lol[1] == lol[2]:
			if lol[0] == lol[1]:
				char = lol[0]
			else:
				char = lol[1]
			ls = []
			if a[1] == char:
				ls.append(int(a[0]))
			if b[1] == char:
				ls.append(int(b[0]))
			if c[1] == char:
				ls.append(int(c[0]))
			ls.sort()
			if ls[0] == ls[1] or ls[0] + 1 == ls[1] or ls[0] + 2 == ls[1]:
				print(1)
			else:
				print(2)
		else:
			print(2)
main()


from itertools import combinations
from collections import defaultdict
from copy import deepcopy
import sys
input = sys.stdin.readline
inf = 100000000000000000
mod = 998244353
B = ['1s', '2s', '3s', '4s', '5s', '6s', '7s', '8s', '9s', '1m', '2m', '3m', '4m', '5m', '6m', '7m', '8m', '9m', '1p', '2p', '3p', '4p', '5p', '6p', '7p', '8p', '9p']
A = list(map(str, input().split()))
A.sort()

def check(a, b, c):
	if C[a][1] == C[b][1] == C[c][1] and ord(C[a][0]) + ord(C[c][0]) == ord(C[b][0]) * 2 and (ord(C[b][0]) - ord(C[a][0]) == 1):
		return 1
	else:
		return 0
if A[-1] == A[-2] == A[-3]:
	print(0)
elif A[-1] == A[-2] or A[-2] == A[-3]:
	print(1)
else:
	if A[0][1] == A[1][1] == A[2][1] and ord(A[0][0]) + ord(A[2][0]) == ord(A[1][0]) * 2 and (ord(A[1][0]) - ord(A[0][0]) == 1):
		print(0)
		sys.exit()
	for b in B:
		C = deepcopy(A)
		C.append(b)
		C.sort()
		for (a, b, c) in combinations([0, 1, 2, 3], 3):
			if check(a, b, c):
				print(1)
				sys.exit()
	print(2)


s = [x for x in input().split()]
n = len(s)
d = {}
for i in range(n):
	if s[i][1] in d:
		d[s[i][1]].append(s[i][0])
	else:
		d[s[i][1]] = [s[i][0]]
f = 1
for k in d.keys():
	d[k].sort()
	c = 0
	if len(set(d[k])) == len(d[k]) - 2:
		f = 0
		print(0)
	elif len(set(d[k])) == len(d[k]) - 1:
		f = 0
		print(1)
	else:
		two = 0
		for i in range(len(d[k]) - 1):
			if int(d[k][i + 1]) - int(d[k][i]) == 1:
				c += 1
			if int(d[k][i + 1]) - int(d[k][i]) == 2:
				two += 1
			if c == 2:
				f = 0
				print(0)
				break
		if c == 1 or two >= 1:
			f = 0
			print(1)
			break
if f == 1:
	print(2)


(s1, s2, s3) = map(str, input().split())
arr = []
arr.append(ord(s1[0]))
arr.append(ord(s2[0]))
arr.append(ord(s3[0]))
flag = 0
if s1 == s2 and s1 == s3:
	flag = 1
	print(0)
if s1[1] == s2[1] and s1[1] == s3[1]:
	arr.sort()
	if arr[1] - arr[0] == 1 and arr[2] - arr[1] == 1:
		if flag == 0:
			flag = 1
			print(0)
if s1 == s2 and s2 != s3 or (s2 == s3 and s3 != s1) or (s1 == s3 and s2 != s1):
	if flag == 0:
		flag = 1
		print(1)
if s1[1] == s2[1] and (abs(arr[1] - arr[0]) == 1 or abs(arr[1] - arr[0]) == 2) or (s2[1] == s3[1] and (abs(arr[2] - arr[1]) == 1 or abs(arr[2] - arr[1]) == 2)) or (s1[1] == s3[1] and (abs(arr[2] - arr[0]) == 1 or abs(arr[2] - arr[0]) == 2)):
	if flag == 0:
		flag = 1
		print(1)
if flag == 0:
	print(2)


arr = input().split()
arr = sorted(arr, key=lambda x: x[0])
no = [int(arr[0][0]), int(arr[1][0]), int(arr[2][0])]
if arr[0] == arr[1] == arr[2] or (no[1] - no[0] == 1 and no[2] - no[1] == 1 and (no[2] - no[0] == 2) and (arr[0][1] == arr[1][1] == arr[2][1])):
	print('0')
elif (arr[0] == arr[1] or arr[1] == arr[2] or arr[0] == arr[2]) or (no[1] - no[0] == 1 and arr[0][1] == arr[1][1]) or (no[2] - no[1] == 1 and arr[1][1] == arr[2][1]) or (no[1] - no[0] == 2 and arr[0][1] == arr[1][1]) or (no[2] - no[1] == 2 and arr[1][1] == arr[2][1]) or (no[2] - no[0] == 2 and arr[2][1] == arr[0][1]) or (no[2] - no[0] == 1 and arr[2][1] == arr[0][1]):
	print('1')
else:
	print('2')


a = input().split()
b = [a[0][1], a[1][1], a[2][1]]
c = sorted([int(a[0][0]), int(a[1][0]), int(a[2][0])])
d = len(list(set(a)))
e = len(list(set(b)))
if e == 1:
	if d == 1:
		print(0)
	elif d == 2:
		print(1)
	elif d == 3:
		if c[1] - c[0] == 1 and c[2] - c[1] == 1:
			print(0)
		elif c[1] - c[0] == 1 or c[2] - c[1] == 1 or c[1] - c[0] == 2 or (c[2] - c[1] == 2):
			print(1)
		else:
			print(2)
elif e == 3:
	print(2)
elif e == 2:
	a.sort()
	if d == 2:
		print(1)
	elif a[0][1] == a[1][1]:
		if int(a[1][0]) - int(a[0][0]) == 1 or int(a[1][0]) - int(a[0][0]) == 2:
			print(1)
		else:
			print(2)
	elif a[1][1] == a[2][1]:
		if int(a[2][0]) - int(a[1][0]) == 1 or int(a[2][0]) - int(a[1][0]) == 2:
			print(1)
		else:
			print(2)
	elif a[0][1] == a[2][1]:
		if int(a[2][0]) - int(a[0][0]) == 1 or int(a[2][0]) - int(a[0][0]) == 2:
			print(1)
		else:
			print(2)


i = input().split()
sets = {'m': [], 'p': [], 's': []}

def check(n):
	m = sets[n]
	m.sort()
	mmin = 2
	for n in range(1, len(m)):
		if m.__contains__(m[n] - 1) and m.__contains__(m[n] - 2):
			mmin = min(0, mmin)
		elif m.__contains__(m[n] - 1) or m.__contains__(m[n] - 2):
			mmin = min(1, mmin)
		mmin = min(3 - m.count(m[n]), mmin)
	return mmin
for card in i:
	sets[card[-1]].append(int(card[:-1]))
print(max(0, min(map(check, sets.keys()))))


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

def rint():
	return map(int, sys.stdin.readline().split())

def is_koutsu():
	if si[0] == si[1] and si[1] == si[2]:
		if sc[0] == sc[1] and sc[1] == sc[2]:
			return True
	return False

def is_shuntsu():
	tmp = sorted(si)
	if sc[0] == sc[1] and sc[1] == sc[2]:
		if tmp[2] == tmp[1] + 1 and tmp[1] == tmp[0] + 1:
			return True
	return False

def is_two_same():
	if s[0] == s[1] or s[0] == s[2] or s[1] == s[2]:
		return True
	else:
		return False

def is_two_adj():
	if abs(si[0] - si[1]) == 1 and sc[0] == sc[1]:
		return True
	elif abs(si[0] - si[2]) == 1 and sc[0] == sc[2]:
		return True
	if abs(si[1] - si[2]) == 1 and sc[1] == sc[2]:
		return True
	return False

def is_two_adj1():
	if abs(si[0] - si[1]) == 2 and sc[0] == sc[1]:
		return True
	elif abs(si[0] - si[2]) == 2 and sc[0] == sc[2]:
		return True
	if abs(si[1] - si[2]) == 2 and sc[1] == sc[2]:
		return True
	return False
	pass
s = input().split()
si = [0, 0, 0]
sc = ['', '', '']
for i in range(3):
	si[i] = int(s[i][0])
for i in range(3):
	sc[i] = s[i][1]
if is_koutsu() or is_shuntsu():
	print(0)
elif is_two_same() or is_two_adj() or is_two_adj1():
	print(1)
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)]
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])
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)


s = input().split()
s = sorted(s)
(s1, s2, s3) = (s[0], s[1], s[2])
if s1 == s2 == s3:
	print(0)
elif int(s1[0]) + 2 == int(s2[0]) + 1 == int(s3[0]) and s1[1] == s2[1] == s3[1]:
	print(0)
elif s1 == s2 or s1 == s3 or s2 == s3:
	print(1)
elif (int(s1[0]) + 1 == int(s2[0]) or int(s1[0]) + 2 == int(s2[0])) and s1[1] == s2[1] or ((int(s1[0]) + 1 == int(s3[0]) or int(s1[0]) + 2 == int(s3[0])) and s1[1] == s3[1]) or ((int(s2[0]) + 1 == int(s3[0]) or int(s2[0]) + 2 == int(s3[0])) and s2[1] == s3[1]):
	print(1)
else:
	print(2)


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:
				result = 1
			base = sortt[y][0]
		result = min(result, cnt1, cnt2)
print(result)


def dbl(x, y):
	if x[1] != y[1]:
		return False
	else:
		return abs(x[0] - y[0]) < 3
p = sorted(map(lambda x: (int(x[0]), x[1]), input().split()))
k = dbl(p[0], p[1]) + dbl(p[0], p[2]) + dbl(p[1], p[2])
if k == 0:
	print(2)
elif k == 3 and 2 * p[1][0] == p[0][0] + p[2][0]:
	print(0)
else:
	print(1)


s = sorted(input().split())
a1 = set(s)
if len(a1) == 1:
	print(0)
else:
	max_len = {}
	ans = 2
	i0 = s[0][1]
	i1 = int(s[0][0])
	for i in s:
		max_len[i[1]] = []
	for i in s:
		max_len[i[1]].append(int(i[0]))
	for i in max_len.keys():
		temp = max_len[i]
		if len(temp) == 3:
			one = temp[1] - temp[0]
			two = temp[2] - temp[1]
			if one == two == 1:
				ans = 0
			elif one == 1 or two == 1 or one == 2 or (two == 2):
				ans = 1
			else:
				ans = 2
		elif len(temp) == 2:
			if temp[1] - temp[0] == 1 or temp[1] - temp[0] == 2:
				ans = 1
			else:
				ans = 2
	print(min(len(a1) - 1, ans))


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
	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 = 1
				if d1[key][j + 1] - d1[key][j] == 2:
					localtwo += 1
				else:
					counttwo = max(counttwo, localtwo)
					localtwo = 1
			count = max(count, local)
			counttwo = max(counttwo, localtwo)
	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))


o = []
n = input()
p = 0
for i in range(3):
	o.insert(i, n[i + p] + n[i + 1 + p])
	p = p + 2
o = sorted(o)
ans = 2
if o[0][1] == o[1][1] and int(o[1][0]) - int(o[0][0]) < 3 or (o[1][1] == o[2][1] and int(o[2][0]) - int(o[1][0]) < 3):
	ans = 1
if o[0][1] == o[2][1] and int(o[2][0]) - int(o[0][0]) < 3:
	ans = 1
if o[0][1] == o[1][1] == o[2][1]:
	if int(o[2][0]) == int(o[1][0]) + 1 and int(o[1][0]) == int(o[0][0]) + 1 or (int(o[2][0]) == int(o[1][0]) and int(o[1][0]) == int(o[0][0])):
		ans = 0
print(ans)


la = sorted(input().split())
res = 2
if int(la[0][0]) == int(la[1][0]) - 1 == int(la[2][0]) - 2:
	if la[0][1] == la[1][1] == la[2][1]:
		res = 0
	elif la[0][1] == la[1][1] or la[1][1] == la[2][1] or la[0][1] == la[2][1]:
		res = 1
elif la[0][0] == la[1][0] == la[2][0]:
	if la[0][1] == la[1][1] == la[2][1]:
		res = 0
	elif la[0][1] == la[1][1] or la[1][1] == la[2][1] or la[0][1] == la[2][1]:
		res = 1
else:
	if int(la[0][0]) == int(la[1][0]) - 2:
		if la[0][1] == la[1][1]:
			res = 1
	if int(la[1][0]) == int(la[2][0]) - 2:
		if la[1][1] == la[2][1]:
			res = 1
	if int(la[0][0]) == int(la[2][0]) - 2:
		if la[0][1] == la[2][1]:
			res = 1
	if int(la[0][0]) == int(la[2][0]) - 1:
		if la[0][1] == la[2][1]:
			res = 1
	if int(la[1][0]) == int(la[2][0]) - 1:
		if la[1][1] == la[2][1]:
			res = 1
	if int(la[0][0]) == int(la[1][0]) - 1:
		if la[0][1] == la[1][1]:
			res = 1
	if int(la[0][0]) == int(la[1][0]):
		if la[0][1] == la[1][1]:
			res = 1
	if int(la[1][0]) == int(la[2][0]):
		if la[1][1] == la[2][1]:
			res = 1
	if int(la[0][0]) == int(la[2][0]):
		if la[0][1] == la[2][1]:
			res = 1
print(res)


d = {'s': 100, 'p': 200, 'm': 300}
z = sorted([int(i[0]) + d[i[1]] for i in map(str, input().split())])
if len(set(z)) == 1 or (z[0] == z[1] - 1 and z[1] == z[2] - 1):
	print(0)
elif (z[0] == z[1] or z[1] == z[2]) or (z[1] - z[0] in [1, 2] or z[2] - z[1] in [1, 2]):
	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()


(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]) + 1 == int(b[0]) or int(a[0]) + 2 == int(b[0])):
	print(1)
elif b[1] == c[1] and (int(b[0]) + 1 == int(c[0]) or int(b[0]) + 2 == int(c[0])):
	print(1)
elif a[1] == c[1] and (int(a[0]) + 1 == int(c[0]) or int(a[0]) + 2 == int(c[0])):
	print(1)
else:
	print(2)


(c1, c2, c3) = input().strip().split()
nums = sorted([int(c1[0]), int(c2[0]), int(c3[0])])
if c1 == c2 == c3:
	print(0)
elif c1[1] == c2[1] == c3[1] and nums[0] == nums[1] - 1 == nums[2] - 2:
	print(0)
elif c1 == c2 or c1 == c3 or c2 == c3:
	print(1)
elif c1[1] == c2[1] and abs(int(c1[0]) - int(c2[0])) in (1, 2) or (c1[1] == c3[1] and abs(int(c1[0]) - int(c3[0])) in (1, 2)) or (c2[1] == c3[1] and abs(int(c2[0]) - int(c3[0])) in (1, 2)):
	print(1)
else:
	print(2)


from collections import defaultdict
t = 1
for test in range(t):
	strs = list(input().split())
	count = defaultdict(int)
	for i in strs:
		count[i] += 1
	suits = 'spm'
	ans = 2
	for i in suits:
		for j in range(1, 10):
			key = str(j) + str(i)
			if count[key] == 3:
				ans = min(ans, 0)
			elif count[key] == 2:
				ans = min(ans, 1)
			key2 = str(j + 1) + str(i)
			key3 = str(j + 2) + str(i)
			if count[key] > 0 and count[key2] > 0 and (count[key3] > 0):
				ans = min(ans, 0)
			elif count[key] > 0 and count[key2] > 0:
				ans = min(ans, 1)
			elif count[key] > 0 and count[key3] > 0:
				ans = min(ans, 1)
	print(ans)


from collections import Counter
ts = Counter((''.join(reversed(t)) for t in input().split()))
t0 = None
run = 0
ans = 3
for (t, c) in sorted(ts.items()):
	if t0 is None or t[0] != t0[0] or int(t[1]) != int(t0[1]) + 1:
		run = 0
	t0 = t
	run += 1
	ans = min(ans, 3 - max(c, run))
for s in 'spm':
	for r in range(1, 10):
		if s + str(r - 1) in ts and s + str(r + 1) in ts:
			ans = min(ans, 1)
print(ans)