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

s = []
c = []
tar = [-1 for i in range(n)]
for i, j in sc:
    s.append(i)
    c.append(j)

for i in range(m):
    if tar[s[i]-1] != -1:
        if tar[s[i]-1] != c[i]:
            print(-1)
            exit()
        else:
            continue
    else:
        tar[s[i]-1] = c[i]
tar1 = tar
for i in range(len(tar1)):
    if tar1[i] == -1:
        tar[i] = 0

if 1 in s and tar[0] == 0:
    print(-1)
else:
    if tar[0]==0:
        tar[0]=1
        print(int("".join(map(str, tar))))
    else:
        print(int("".join(map(str, tar))))
