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