import sys
n,m = map(int,input().split())
tmp = ['0'] * n
for _ in range(m):
    lis = list(map(int,input().split()))
    if lis[0] > n:
        print('-1')
        sys.exit()
    if tmp[lis[0]-1] !='0' and tmp[lis[0]-1] != lis[1]:
        #print(tmp)
        #print(int(lis[0])-1],lis[1])
        print('-1')
        sys.exit()
    tmp[lis[0]-1] = lis[1]
#print(tmp)
if n ==1 and tmp[0] == '0':
    print('0')
elif tmp[0] == '0' or tmp[0] == 0:
    print('-1')
else:
    #print(tmp)
    #print(tmp) [7, '0', 2]
    tt = []
    for t in tmp:
        if type(t) is int:
            tt.append(str(t))
        else:
            tt.append(t)
    print(str("".join(tt)))