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

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)
myans = ''
mycnt = 0
for m in mylist:
    if m == 0 and (mycnt == 0 or float('INF')):
        print(-1)
        sys.exit()
    elif m == float('INF'):
       myans += str(0)
    else:
        myans += str(m)
        mycnt += 1
print(myans)