import sys
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]

l = [0 for i in range(n)]
set_sc = [[] for i in range(n)]

for i in range(m):
    set_sc[sc[i][0]-1].append(sc[i][1])

for i in range(m):
    if len(set(set_sc[i])) > 1:
        print(-1)
        sys.exit()

if set_sc[0][0] == 0:
    print(-1)
    sys.exit()

for i in range(n):
    if len(set_sc[i]) == 0:
        continue
    l[i] = set_sc[i][0]

l = list(map(str,l))
print(''.join(l))