n,m = map(int,input().split()) graph=[[] for _ in range(n)] for i in range(m): a,b = map(int,input().split()) graph[a-1].append(b-1) c1=0 c2=0 for i in range(n): if len(graph[i])%2==1: c1+=1 else: c2+=1 if c1-2 > 0: print(abs(c1-2)) elif c1-2 == 0 or c1 == 0: print(0) else: print(-1)