stdin = open(0).read().split('\n')
N, M = map(int,stdin[0].split())
num=['a']*N
for i in range(M):
    s, c = stdin[i+1].split()
    if not num[int(s)-1].isdecimal():
        num[int(s)-1]=c
    elif num[int(s)-1]!=c:
        print(-1)
        exit()
ans = "".join(num).replace('a', '0')
print(int(ans) if ans[0]!='0' else -1)