n, m = map(int, input().split())
s = ['0'] * m
c = ['0'] * m

for i in range(m):
    s[i], c[i] = map(str, input().split())

flg = [0] * n
ans = ['0'] * n

for i in range(m):
    if ans[int(s[i])-1] == '0':
        ans[int(s[i])-1] = c[i]
        flg[int(s[i])-1] = 1
    elif ans[int(s[i])-1] == c[i]:
        pass
    else:
        print(-1)
        exit()

for i in range(n):
    if flg[i] == 0 and i == 0:
        ans[i] = '1'
    else:
        pass

if len(ans) > 1 and ans[0] == '0':
    print(-1)
    exit()

print(''.join(ans))