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.

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.

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

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

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

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

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

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

    return 3-ans

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

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

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

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

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

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

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

'''

1. Figure out min number to get a kontsu

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

2. Figure out min number to get a mentsu

   Sort the cards

   Do a while loop

   While i is < len(lst)

     Count # of consecutive cards

     Move j until index of the last consecutive card

'''

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

def min_koutsu(cards):
    counter = {}

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

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

def min_shuntsu(cards):
    '''
    Cases:

    3 same:

    2 same: either consecutive

    7p 8p or 7p 9p

    '''

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

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

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

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

    return 2

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

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

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

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

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

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

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)

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

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

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

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

    so i guess better to digits

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

    # sorted so smallest to largest

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

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

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

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

main()

# In[10]:

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

# In[12]:

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

# In[13]:

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

# In[15]:

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

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

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

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

from collections import Counter

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

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

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

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

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

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

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

        if not gaps:
            return 2

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

a = input().split()

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

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

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

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

print(min(hello))

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

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

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

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

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

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

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

#using namespace std;

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

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

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

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

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

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

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)

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

    return True

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

    return True

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

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

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

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

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

    else:
        print(2)

main()

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

d=dict()

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

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

maxi=0

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

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

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

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

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

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

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

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

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

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)

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

import sys,math

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

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

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

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

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

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

tiles = read_string_list()

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

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

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

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

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

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

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

#no luck
print(2)

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)

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)

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

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

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

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

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

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

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

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

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

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

    print(ans)

if __name__ == "__main__":
    main()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

print(min(ans , 3 - t))

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

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

    return 2

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

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

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

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

print(2)
exit(0)

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

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

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

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

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

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

    arr=meth(arr)
    res+=1

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

"""

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

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

# Main

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

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

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

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

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

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

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

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

if sol == None:
	sol = 2

print sol

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

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

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

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

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

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)

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)

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

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

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

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

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

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)

import sys

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

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

q=d.values()

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

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

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)

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)

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

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

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

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

print(ans)

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

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

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

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

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

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

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

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

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

main()

from __future__ import print_function
import sys

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

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

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

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

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

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

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

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

    arr.sort()

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

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

def solve():

    cards = input().split()

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

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

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

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

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

    print(3 - _n)

solve()

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

print(min_draw)

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

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

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

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

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

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

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

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

# 3m 9m 2m

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

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

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

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

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

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

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

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

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

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

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

print(min_draw)

import sys

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

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

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

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

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

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

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

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

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

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

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

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

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

main()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# target Specialist

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

    * Readability counts *

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

"""

from __future__ import division, print_function

import os,sys
from io import BytesIO, IOBase

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

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

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

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

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

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

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

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

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

def main():

    #for _ in range(ii()):

    a,b,c=mi()

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

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

    else:

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

        l=sort2(l)

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

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

        else:
            print(2)

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

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

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

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

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

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

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

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

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

# endregion

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

# Comment Read()

#Tokitsukaze and Mahjong
DEBUG = False

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

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

a=input().split()

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

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

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

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

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

else:
    print(2);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    ans = float("inf")

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

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

    print(ans)

if __name__ == "__main__":
    solve()

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

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

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

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

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

from sys import stdin
from math import fabs

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

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

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

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

print(need(x,y,z))

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

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

    ans = float("inf")

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

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

if __name__ == "__main__":
    solve()

#Tokitsukaze and Mahjong
DEBUG = False

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

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

a=input().split()

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

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

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

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

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

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

else:
    print(2);

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

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

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

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

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

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

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

	if temp > s:
		s = temp

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

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

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

result = 2

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

print(result)

import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

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

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

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

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

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

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

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

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

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

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

	else:

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

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

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

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

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

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

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

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

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

else:
    print(2)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# Main

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

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

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

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

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

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

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

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

if sol == None:
	sol = 2

print sol

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

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

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

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

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

    so i guess better to digits

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

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

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

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

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

main()

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

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

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

d=dict()

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

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

maxi=0

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

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

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

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

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

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

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

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

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