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, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s.

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

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

Here are some useful definitions in this game:

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



Some examples: 

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



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

Input

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

Output

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

Examples

Input


1s 2s 3s


Output


0


Input


9m 9m 9m


Output


0


Input


3p 9m 2p


Output


1

Note

In the first example, Tokitsukaze already has a shuntsu.

In the second example, Tokitsukaze already has a koutsu.

In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile — 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
# so basically what we want to do is get some ice, then we get salt and we salt
# the ice. it becomes salty ice, on top of which you add lovely flavors like
# vanilla and chocolate sauce to add to the taste. from that point, you got some
# of that great ice cream. but suppose you want toppings; what about sprinkles
# or bits of fruit such as strawberry mixed in? i got you. add them. once you do,
# you got a great ice cream to throw on your friends' faces so they hate you
# forever. yay.

# men, cow, shun, man, pin, shoe ... what even is this problem?

tup = lambda s: (int(s[0]), s[1])

mlist = []
plist = []
slist = []

ilist = input().split()

# this is the point when you realize you have no friends. :(

for i in ilist:
    if i[1] == "m":
        mlist.append(int(i[0]))
    if i[1] == "p":
        plist.append(int(i[0]))
    if i[1] == "s":
        slist.append(int(i[0]))

mlist.sort()
plist.sort()
slist.sort()

mdiff = []
pdiff = []
sdiff = []

for i in range(len(mlist) - 1):
    mdiff.append(mlist[i+1] - mlist[i])
for i in range(len(plist) - 1):
    pdiff.append(plist[i+1] - plist[i])
for i in range(len(slist) - 1):
    sdiff.append(slist[i+1] - slist[i])

mi0 = False
mi1 = False
mi2 = False
consec0 = False
consec1 = False

for i in range(len(mdiff)):
    if mdiff[i] == 0:
        if (not isinstance(mi0, bool)) & (mi0 == i-1):
            consec0 = True
            break
        mi0 = i
    if mdiff[i] == 1:
        if (not isinstance(mi1, bool)) & (mi1 == i-1):
            consec1 = True
            break
        mi1 = i
    if mdiff[i] == 2:
        mi2 = i

pi0 = False
pi1 = False
pi2 = False

for i in range(len(pdiff)):
    if pdiff[i] == 0:
        if (not isinstance(pi0, bool)) & (pi0 == i-1):
            consec0 = True
            break
        pi0 = i
    if pdiff[i] == 1:
        if (not isinstance(pi1, bool)) & (pi1 == i-1):
            consec1 = True
            break
        pi1 = i
    if pdiff[i] == 2:
        pi2 = i

si0 = False
si1 = False
si2 = False

for i in range(len(sdiff)):
    if sdiff[i] == 0:
        if (not isinstance(si0, bool)) & (si0 == i-1):
            consec0 = True
            break
        si0 = i
    if sdiff[i] == 1:
        if (not isinstance(si1, bool)) & (si1 == i-1):
            consec1 = True
            break
        si1 = i
    if sdiff[i] == 2:
        si2 = i

if consec0:
    print(0)
elif not isinstance(mi0, bool):
    print(1)
elif not isinstance(pi0, bool):
    print(1)
elif not isinstance(si0, bool):
    print(1)
    
elif consec1:
    print(0)
elif not isinstance(mi1, bool):
    print(1)
elif not isinstance(pi1, bool):
    print(1)
elif not isinstance(si1, bool):
    print(1)
    
elif not isinstance(mi2, bool):
    print(1)
elif not isinstance(pi2, bool):
    print(1)
elif not isinstance(si2, bool):
    print(1)

else:
    print(2)
