n,m = map(int, input().split())
a = [0]*n
Flag = True
for i in range(m):
    s,c = map(int, input().split())
    if a[s-1]==0 or a[s-1]==c:
        a[s-1] = c
    else:
        Flag = False
if len(a) != 1 and a[0] == 0:
    Flag = False
print("".join(map(str,a)) if Flag else -1)