def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

N,M = map(int,input().split())
SC = [list(map(int,input().split())) for i in range(M)]




for i in range(M):
    for j in range(M):
        if SC[i][0] == SC[j][0] and SC[i][1] != SC[j][1]:
            print(-1)
            exit()
if [1,0] in SC and N == 1:
    print(0)
    exit()
if [1,0] in SC:
    print(-1)
    exit()

l = []
SC = get_unique_list(SC)

for i in range(1,N+1):
    for j in range(len(SC)):
        if SC[j][0] == i:
            a = SC[j]
            l.append(a)

s = ["0"]*N
for i in range(len(l)):
    s[l[i][0]-1] = str(l[i][1])


if s[0] == "0":
    s[0] = "1"


for i in s:
    print(i,end='')
