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

#入力がなければ1桁の0だけ答えとなる
if M == 0:
    if N == 1:
        print(0)
        sys.exit()
    else:
        print(-1)
        sys.exit()

mylist = [float('INF') for n in range(N)]

#print(mylist)

for n in range(M):
    s, c  = map(int, input().split())
    if mylist[s-1] == float('INF') or mylist[s-1] == c:
        mylist[s-1] = c
    #桁の重複があればだめ
    else:
        print(-1)
        sys.exit()
#print(mylist)
if N == 1 and mylist[0] == 0:
    print(0)
    sys.exit()


myans = ''
mycnt = 0
for m in mylist:
    #先頭が0はだめ
    if m == 0 and mycnt == 0:
        print(-1)
        sys.exit()
    #infの場合
    elif m == float('INF'):
        if mycnt != 0:
            myans += str(0)
        else:
            myans += str(1)
        mycnt += 1
    else:
        myans += str(m)
        mycnt += 1
print(myans)