import sys 
a = list(map(int,input().split()))

N = a[0]
M = a[1]

b = ['0']*N

for i in range(0,M):
    x = list(map(str,input().split()))
    if b[int(x[0])-1] != '0' and b[int(x[0])-1] != x[1]:
        print('-1')
        sys.exit()
    elif x[0] == '1' and x[1] == '0':
        print('-1')
        sys.exit()
    else:
        b[int(x[0])-1] = x[1]

if N == 2:
    if b[0] == '0' and int(b[1]) != 0:
        b[0] = '1'

if N == 3:
    if b[0] == '0' and (int(b[1]) != 0 or int(b[2]) != 0):
        b[0] = '1'
ans = ''.join(b)
print(ans)


