n, m = map(int, input().split())

num = [0]*n
out = False
for _ in range(m):
    s, c = map(int, input().split())
    if num[s-1]==0:
        num[s-1] = c
    elif num[s-1]!=c:
        out = True
ans = 100*num[0]+10*num[1]+num[2]
if out or ans==0:
    print(-1)
else:
    print(ans)