import sys

N,M = map(int,input().split())
Data = []
for _ in range(M):
    s,c = map(int,input().split())
    Data.append([s,c])

Num = [-1]*N
flag = True
for i in range(M):
    s,c = Data[i]
    if Num[s-1] == -1:
        Num[s-1] = c
    else:
        if Num[s-1] != c:
            print(-1)
            sys.exit()
if N == 1:
    print(Num[0])

if N == 2:
    if Num[0] == 0:
        print(-1)
    else:
        if Num[0] == -1:
            Num[0] = 1
        if Num[1] == -1:
            Num[1] = 0
        print(Num[0]*10+Num[1])

if N == 3:
    if Num[0] == 0:
        print(-1)
    else:
        if Num[0] == -1:
            Num[0] = 1
        if Num[1] == -1:
            Num[1] = 0
        if Num[2] == -1:
            Num[2] = 0
        print(Num[0]*100+Num[1]*10+Num[2])
