import sys sys.setrecursionlimit(1 << 25) def main(): import sys input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]) idx += 1 M = int(data[idx]) idx += 1 edges = [] for _ in range(M): u = int(data[idx]) idx += 1 v = int(data[idx]) idx += 1 edges.append((u, v)) # Compute connected components in undirected graph parent = list(range(N+1)) def find(u): while parent[u] != u: parent[u] = parent[parent[u]] u = parent[u] return u def union(u, v): u_root = find(u) v_root = find(v) if u_root != v_root: parent[v_root] = u_root for u, v in edges: union(u, v) # Count connected components visited = set() C = 0 for v in range(1, N+1): root = find(v) if root not in visited: visited.add(root) C += 1 # Compute D_v for each vertex out = [0] * (N + 1) in_ = [0] * (N + 1) for u, v in edges: out[u] += 1 in_[v] += 1 D = [out[v] - in_[v] for v in range(N+1)] S = sum(1 for v in range(1, N+1) if D[v] != 0) if S == 0: if C == 1: print(0) else: print(C - 1) elif S == 2: a = 0 b = 0 for v in range(1, N+1): if D[v] != 0: if D[v] > 0: a = D[v] else: b = D[v] required_degree = a - 1 required_connection = max(0, C - 1) minimal_edges = max(required_degree, required_connection) print(minimal_edges) else: required_degree = (S - 2 + 1) // 2 required_connection = max(0, C - 1) minimal_edges = max(required_degree, required_connection) print(minimal_edges) if __name__ == "__main__": main()