n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
s,c = zip(*sc)

arr = [0 for i in range(n)]

for i in range(m):
    if arr[s[i]-1] != 0 and arr[s[i]-1] != c[i]:
        print(-1)
        exit()
    if n != 1 and s[i]-1 == 0 and c[i] == 0:
        print(-1)
        exit()
    else:
        arr[s[i]-1] = c[i]

if n == 1 and arr[0] == 0:
    print(0)
    exit()

if arr[0] == 0:
    arr[0] = 1

print("".join(map(str,arr)))