n,m = map(int,input().split())
d = [0 for _ in range(n)]
d[0] = 1
sarr = []
if m == 0:
    d[0] = 0
for i in range(m):
    s,c = map(int,input().split())
    if s == 1 and c == 0 and not n == 1:
        print(-1)
        exit()
    if s in sarr and c != d[s-1]:
        print(-1)
        exit()
    d[s-1] = c
    sarr.append(s)
    #print(sarr)
    #print(d)
ans = ''
for i in range(n):
    ans += str(d[i])
print(ans)
