import sys
N, M = map(int, input().split())
ls = ['' for i in range(N)]

for i in range(M):
    s, c = map(int, input().split())
    if ls[s-1] == '':
        ls[s-1] = str(c)
    elif ls[s-1] != str(c):
        print(-1)
        sys.exit()

if ls[0] == '0' and len(ls) == 1:
    print(0)
    sys.exit()
elif ls[0] == '0' and len(ls) != 1:
    ls[0] = '1'

ans = ''
for x in ls:
    if x != '':
        ans += x
    else:
        ans += '0'
print(ans)