N, M = map(int, input().split())

X = ["x"]*N
flag = True

for i in range(M):
    s, c = map(int, input().split())
    if X[s-1] == "x":
        X[s-1] = c
    elif X[s-1] != c:
        flag = False
        break

if N > 1 and X[0] == 0:
    flag = False

if X[0] == "x":
    X[0] = 1

if flag:
    for i in X:
        if i == "x":
            print(0 ,end="")
        else:
            print(i ,end="")
else:
    print(-1)