n,m = map(int,input().split())
if m == 0:
    if n == 1:
        print(0)
        exit()
    else:
        print(-1)
        exit()

lists = [list(map(int,input().split())) for i in range(m)]
keta = ["0"]*3
Max = -999999
Min = 99999999
tmp = lists[0][0]
for i,j in lists:
    keta[i-1] = str(j)
    Max = max(i,Max)
    num = "".join(keta)
    ans = int(num)
    if tmp == i:
        Min = min(ans,Min)
        keta = list(str(Min).zfill(3))
    else:
        Min = ans
if len(str(Min)) == n:
    print(Min)
else:
    print(-1)


