import sys
from collections import defaultdict

def solve():
    lines = sys.stdin.read().strip().split('\n')
    if not lines: 
        return

    # Adjacency list simulating capacities
    adj = defaultdict(dict)

    parsing_caps = False
    for line in lines:
        line = line.strip()
        if not line: continue
        if line.startswith("Capacities:"):
            parsing_caps = True
            continue
        
        # Read formatted edge capabilities safely
        if parsing_caps:
            line = line.replace('→', '->')
            if '->' in line and '=' in line:
                parts = line.split('=')
                cap = int(parts[1].strip())
                edge_parts = parts[0].split('->')
                u = edge_parts[0].strip()
                v = edge_parts[1].strip()
                
                # Setup Capacity in Residual Graph
                adj[u][v] = cap
                if u not in adj[v]:
                    adj[v][u] = 0 # Initialize back-edge with 0 capacity

    # Identifying Source and Sink statically as defined
    source = 'S'
    sink = 'T'

    # Depth First Search to find shortest/available augmenting path
    def dfs(u, min_cap, visited):
        if u == sink:
            return min_cap
        
        visited.add(u)
        for v, cap in adj[u].items():
            if v not in visited and cap > 0:
                # Push bottleneck capacity further down
                pushed = dfs(v, min(min_cap, cap), visited)
                
                # If flow reached the sink successfully, mutate the graph
                if pushed > 0:
                    adj[u][v] -= pushed  # Decrease forward residual capacity
                    adj[v][u] += pushed  # Increase backward residual capacity
                    return pushed
        return 0

    # Iteratively run FF Method until no augmenting paths are present
    max_flow = 0
    while True:
        visited = set()
        pushed = dfs(source, float('inf'), visited)
        if pushed == 0:
            break
        max_flow += pushed

    print(f"Maximum Flow = {max_flow}")

if __name__ == "__main__":
    solve()

"""
=== SAMPLE INPUT ===
Vertices: {S, A, B, T}
Capacities:
S → A = 10
S → B = 5
A → B = 15
A → T = 10
B → T = 10

=== SAMPLE OUTPUT ===
Maximum Flow = 15
"""