N,M = [int(i) for i in input().split()]
s = [0] * M
c = [0] * M
for i in range(M):
    s[i],c[i] = [int(j) for j in input().split()]
find = [False] * N
ans = ['0'] * N
for i in range(M):
    sa = s[i] -1
    ca = c[i]
    if find[sa] == False:
        find[sa] = True
        ans[sa] = str(ca)
        continue
    if find[sa]:
        if ans[sa] != str(ca):
            print('-1')
            exit()
if N != 1:
    if ans[0] == '0':
        print('-1')
        exit()
else:
    print(''.join(ans))