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].

Difficulty: interview

Starter code:

Solutions:
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
            else :
                if 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)

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)

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

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().split()
s.sort()
if s[0] == s[1] == s[2]:
	print(0)
	return
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)
		return
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)
	return
if s[0] == s[1] or s[1] == s[2] or s[0] == s[2]:
	print(1)
	return
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)


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
# Shuntsu
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 sys import stdin, stdout, exit

t1, t2, t3 = stdin.readline().split()

if t1 == t2 and t2 == t3:
    print(0)
    return

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)
    return
if ns[0] + 2 >= ns[1] and ss[1] == ss[0]:
    print(1)
    return
if ns[1] + 2 >= ns[2] and ss[1] == ss[2]:
    print(1)
    return
if ns[0] + 2 >= ns[2] and ss[0] == ss[2]:
    print(1)
    return
if ts[0] == ts[1] or ts[1] == ts[2] or ts[2] == ts[0]:
    print(1)
    return

print(2)




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)
	else:
		if(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)
	else:
		if(len(a[i])>0):
			ko=min(ko,2)


print(min(ans,ko))





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)

from sys import stdin, stdout

#N = int(input())

#arr = [int(x) for x in stdin.readline().split()]

s = input()

s = s.split(' ')

#print(s)

M = [0]*9
P = [0]*9
S = [0]*9

for pile in s:
    pile = list(pile)
    #print(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)
        
    


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)

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




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

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)


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(s)
# print(hand)
print(min_steps_needed)

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


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

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


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)
    


# -*- coding: utf-8 -*-
"""
Created on Fri Jul 12 17:39:54 2019

@author: Hamadeh
"""

# -*- coding: utf-8 -*-
"""
Created on Fri Jul 12 17:33:49 2019

@author: Hamadeh
"""

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): #n is number of inputs, t is type to be casted
        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):
        #usable up to 10 thousand
        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):
        #1000000 tops
        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)

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')
  else:
    if 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')
    else:
      if num[2] - num[0] in [1, 2]:
        print('1')
      else:
        print('2')

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