n,m = map(int,input().split())
st = ['']*n
f = 1
for i in range(m):
    s,c = map(int,input().split())
    s -= 1
    if n == 1 and s == 0 and c == 0:
        f = 0
    elif st[s] == '' or st[s] == str(c):
        st[s] = str(c)
    else:
        f = 0

for j in range(n):
    if st[j] == '':
        st[j] = '0'

if f:
    print(''.join(st))
else:
    print(-1)