import sys

n , m = map(int,input().split())
if m == 0:
    m += 1
a = []

for i in range(m):
    a.append(list(map(int,input().split())))

ans = [-1] * n

for j in a:
    if ans[j[0]-1] == -1:
        if j[0] > n:
            print(-1)
            sys.exit()
        else:
            ans[j[0]-1] = j[1]
    elif ans[j[0]-1] == j[1]:
        continue
    else:
        print(-1)
        sys.exit()

if n == 3 and ans[0] == -1 and ans[1] == 0:
    ans[0] = 1

for index,l in enumerate(ans):
    if l == -1 :
        ans[index] = 0
    elif index == 0 and n != 1:
        if ans[index] == 0:
            print(-1)
            sys.exit()

for index , x in enumerate(ans):
    ans[index] = str(ans[index])

b = "".join(ans)

if b == "000" or b == "00" or b == "0":
    print(0)
else:
    print(int(b))