n, m = map(int, input().split())
num = [-1]*n
ans = 0

for i in range(m):
    s, c = map(int, input().split())
    if num[s-1] == -1:
        num[s-1] = c
    else:
        if num[s-1] != c:
            print(-1)
            exit()
    
    
for i in range(n):
    if num[i] != -1:
        ans += num[i]*(10**(n-(i+1)))

if len(str(ans)) == n:
    print(ans)
else:
    print(-1)