import sys
n,m = map(int,input().split())
lis = [list(map(int,input().split())) for _ in range(m)]
dic = {}
for l in lis:
    if l[0] not in dic:
        dic[l[0]] = l[1]
    else:
        if dic[l[0]] != l[1]:
            print('-1')
            sys.exit()
dct = sorted(dic.items())
tmp = ['0'] * n
#print(dct)
for d in dct:
    tmp[d[0]-1] = str(d[1])
if n ==1 and tmp[0] == '0':
    print('0')
elif tmp[0] == '0':
    print('-1')
else:
    print("".join(tmp))