import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd dout = defaultdict(int) din = defaultdict(int) n,m = map(int,input().split()) for i in range(m): a,b = map(int,input().split()) dout[b-1]+=1 din[a-1]+=1 cnt1=0 cnt2=0 c1max=0 c2max=0 for i in range(n): if dout[i] == din[i]: continue elif dout[i] > din[i]: cnt1+= dout[i] - din[i] c1max=max(cnt1,c1max) else: cnt2+= din[i] - dout[i] c2max=max(cnt1,c1max) if cnt1+cnt2 == 0: print(0) else: print((cnt1+cnt2)//2-1)