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

num = [0]*n
for d in mat:
    if d[0] == 1 and d[1] == 0:
        print(-1)
        exit()
    
    if num[d[0]-1]== 0 or num[d[0]-1] == d[1]:
        num[d[0]-1] = d[1]
    else:
        print(-1)
        exit()

if num[0] == 0:
    num[0] = 1

ans = ''
for n in num:
    ans += str(n)

print(ans)