# Acceptance of input



import sys



file_input = sys.stdin



V, E = list(map(int, file_input.readline().split()))



adj_mat = [[0] * V for i in range(V)]



for line in file_input:

    u, v, c = list(map(int, line.split()))

    adj_mat[u][v] = c



# Ford???Fulkerson algorithm



import collections



# BFS for residual capacity network

def bfs(start, goal, parent):

    unvisited = [True] * V

    queue = collections.deque()

    queue.append(start)

    unvisited[start] = False

    while queue:

        u = queue.popleft()

        for v, flow in enumerate(adj_mat[u]):

            if unvisited[v] and (flow > 0):

                queue.append(v)

                unvisited[v] = False

                parent[v] = u

    return not unvisited[goal]



def ford_fulkerson(source, sink):

    parent = [None] * V

    max_flow = 0

    while bfs(source, sink, parent):

        aug_path_flow = 10000

        v = sink

        while (v != source):

            aug_path_flow = min(aug_path_flow, adj_mat[parent[v]][v])

            v = parent[v]

        max_flow += aug_path_flow

        v = sink

        while (v != source):

            u = parent[v]

            adj_mat[u][v] -= aug_path_flow

            adj_mat[v][u] += aug_path_flow

            v = u

    return max_flow



# output

print((ford_fulkerson(0, V - 1)))
# Acceptance of input



import sys



file_input = sys.stdin



V, E = list(map(int, file_input.readline().split()))



adj_mat = [[0] * V for i in range(V)]



for line in file_input:

    u, v, c = list(map(int, line.split()))

    adj_mat[u][v] = c



# Ford???Fulkerson algorithm



import collections



# BFS for residual capacity network

def bfs(start, goal, parent):

    flow = [0] * V

    queue = collections.deque()

    queue.append(start)

    flow[start] = 10000

    while queue:

        u = queue.popleft()

        for v, r_capacity in enumerate(adj_mat[u]):

            if not flow[v] and (r_capacity > 0):

                queue.append(v)

                flow[v] = min(flow[u], r_capacity)

                parent[v] = u

                if v == goal:

                    return flow[goal]



def ford_fulkerson(source, sink):

    max_flow = 0

    while True:

        parent = [None] * V

        aug_path_flow = bfs(source, sink, parent)

        if aug_path_flow:

            max_flow += aug_path_flow

            v = sink

            while (v != source):

                u = parent[v]

                adj_mat[u][v] -= aug_path_flow

                adj_mat[v][u] += aug_path_flow

                v = u

        else:

            break

    return max_flow



# output

print((ford_fulkerson(0, V - 1)))
# Acceptance of input
import sys

file_input = sys.stdin
V, E = list(map(int, file_input.readline().split()))
adj_mat = [[0] * V for i in range(V)]
for line in file_input:
    u, v, c = list(map(int, line.split()))
    adj_mat[u][v] = c
# Ford???Fulkerson algorithm
import collections

# BFS for residual capacity network
def bfs(start, goal, parent):
    unvisited = [True] * V
    queue = collections.deque()
    queue.append(start)
    unvisited[start] = False
    while queue:
        u = queue.popleft()
        for v, flow in enumerate(adj_mat[u]):
            if unvisited[v] and (flow > 0):
                queue.append(v)
                unvisited[v] = False
                parent[v] = u
    return not unvisited[goal]


def ford_fulkerson(source, sink):
    parent = [None] * V
    max_flow = 0
    while bfs(source, sink, parent):
        aug_path_flow = 10000
        v = sink
        while v != source:
            aug_path_flow = min(aug_path_flow, adj_mat[parent[v]][v])
            v = parent[v]
        max_flow += aug_path_flow
        v = sink
        while v != source:
            u = parent[v]
            adj_mat[u][v] -= aug_path_flow
            adj_mat[v][u] += aug_path_flow
            v = u
    return max_flow


# output
print((ford_fulkerson(0, V - 1)))

# Acceptance of input
import sys

file_input = sys.stdin
V, E = list(map(int, file_input.readline().split()))
adj_mat = [[0] * V for i in range(V)]
for line in file_input:
    u, v, c = list(map(int, line.split()))
    adj_mat[u][v] = c
# Ford???Fulkerson algorithm
import collections

# BFS for residual capacity network
def bfs(start, goal, parent):
    flow = [0] * V
    queue = collections.deque()
    queue.append(start)
    flow[start] = 10000
    while queue:
        u = queue.popleft()
        for v, r_capacity in enumerate(adj_mat[u]):
            if not flow[v] and (r_capacity > 0):
                queue.append(v)
                flow[v] = min(flow[u], r_capacity)
                parent[v] = u
                if v == goal:
                    return flow[goal]


def ford_fulkerson(source, sink):
    max_flow = 0
    while True:
        parent = [None] * V
        aug_path_flow = bfs(source, sink, parent)
        if aug_path_flow:
            max_flow += aug_path_flow
            v = sink
            while v != source:
                u = parent[v]
                adj_mat[u][v] -= aug_path_flow
                adj_mat[v][u] += aug_path_flow
                v = u
        else:
            break
    return max_flow


# output
print((ford_fulkerson(0, V - 1)))

-    unvisited = [True] * V +    flow = [0] * V -    unvisited[start] = False +    flow[start] = 10000 -        for v, flow in enumerate(adj_mat[u]): -            if unvisited[v] and (flow > 0): +        for v, r_capacity in enumerate(adj_mat[u]): +            if not flow[v] and (r_capacity > 0): -                unvisited[v] = False +                flow[v] = min(flow[u], r_capacity) -    return not unvisited[goal] +                if v == goal: +                    return flow[goal] -    parent = [None] * V -    while bfs(source, sink, parent): -        aug_path_flow = 10000 -        v = sink -        while v != source: -            aug_path_flow = min(aug_path_flow, adj_mat[parent[v]][v]) -            v = parent[v] -        max_flow += aug_path_flow -        v = sink -        while v != source: -            u = parent[v] -            adj_mat[u][v] -= aug_path_flow -            adj_mat[v][u] += aug_path_flow -            v = u +    while True: +        parent = [None] * V +        aug_path_flow = bfs(source, sink, parent) +        if aug_path_flow: +            max_flow += aug_path_flow +            v = sink +            while v != source: +                u = parent[v] +                adj_mat[u][v] -= aug_path_flow +                adj_mat[v][u] += aug_path_flow +                v = u +        else: +            break