n,m = map(int,input().split())
sc = [ list(map(int,input().split())) for _ in range(m) ]

a = [-1]*n
# print(a)

# import numpy as np
# sc = np.array(sc)

for i in range(m):
    if a[sc[i][0]-1] == -1:
        a[sc[i][0]-1] = sc[i][1]
    else:
        if a[sc[i][0]-1] == sc[i][1]:
            pass
        else:
            print(-1)
            exit()

# print(a)

for i in range(len(a)):
    if a[i]==-1:
        a[i] = 0

# print(a)

if a[0]==0:
    print(-1)
else:
    print("".join(list(map(str,a))))