def minimum_moves(n, instructions):
# Define the four tiles
tiles = ["up", "down", "right", "left"]
# Initialize a dictionary to store the minimum moves required to each position
dp = {tile: float("inf") for tile in tiles}
# Start with any position (0 moves initially)
for tile in tiles:
dp[tile] = 0
for instr in instructions:
new_dp = {tile: float("inf") for tile in tiles}
for current_tile in tiles:
for target_tile in tiles:
# If same tile, no movement needed; otherwise, 1 move
cost = 0 if current_tile == target_tile else 1
new_dp[target_tile] = min(new_dp[target_tile], dp[current_tile] + cost)
dp = new_dp
# Find the minimum moves among all final positions
return min(dp.values())
# Input
n = int(input())
instructions = [input().strip() for _ in range(n)]
# Output
print(minimum_moves(n, instructions))
ZGVmIG1pbmltdW1fbW92ZXMobiwgaW5zdHJ1Y3Rpb25zKToKICAgICMgRGVmaW5lIHRoZSBmb3VyIHRpbGVzCiAgICB0aWxlcyA9IFsidXAiLCAiZG93biIsICJyaWdodCIsICJsZWZ0Il0KICAgIAogICAgIyBJbml0aWFsaXplIGEgZGljdGlvbmFyeSB0byBzdG9yZSB0aGUgbWluaW11bSBtb3ZlcyByZXF1aXJlZCB0byBlYWNoIHBvc2l0aW9uCiAgICBkcCA9IHt0aWxlOiBmbG9hdCgiaW5mIikgZm9yIHRpbGUgaW4gdGlsZXN9CiAgICAKICAgICMgU3RhcnQgd2l0aCBhbnkgcG9zaXRpb24gKDAgbW92ZXMgaW5pdGlhbGx5KQogICAgZm9yIHRpbGUgaW4gdGlsZXM6CiAgICAgICAgZHBbdGlsZV0gPSAwCgogICAgZm9yIGluc3RyIGluIGluc3RydWN0aW9uczoKICAgICAgICBuZXdfZHAgPSB7dGlsZTogZmxvYXQoImluZiIpIGZvciB0aWxlIGluIHRpbGVzfQogICAgICAgIGZvciBjdXJyZW50X3RpbGUgaW4gdGlsZXM6CiAgICAgICAgICAgIGZvciB0YXJnZXRfdGlsZSBpbiB0aWxlczoKICAgICAgICAgICAgICAgICMgSWYgc2FtZSB0aWxlLCBubyBtb3ZlbWVudCBuZWVkZWQ7IG90aGVy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