import itertools
import functools
import math
from collections import Counter
from itertools import combinations

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

ans = [0] * 10
for i in range(N):
    ans[i] = -1

for i in range(M):
    S,C=map(int,input().split())
    if S > N and C != 0:
        print(-1)
        exit()
    if ans[S-1] != -1 and ans[S-1] != C:
        print(-1)
        exit()
    ans[S-1] = C

if N >=2 and ans[0] == "0":
    print(-1)
    exit()

for i in range(10**N):
    chk = "000" + str(i)
    l = len(chk)
    chk = chk[l-3:]
    for j in range(N):
        if int(ans[j]) == -1:
            continue
        elif int(ans[j]) != int(chk[j]):
            break
        if j == N - 1:
            if len(str(i)) == N:
                print(i)
                exit()

print(-1)