N, M = map(int, input().split())

ans = []
for i in range(N):
    ans.append('a')

f = True
for i in range(M):
    s, c = map(int, input().split())

    if ans[s - 1] == 'a':
        ans[s - 1] = str(c)

    elif ans[s - 1] != str(c):
        f = False
        break

for i in range(N - 1):
    if ans[0] == 'a':
        ans.pop(0)
    elif ans[0] == '0':
        f = False
        break

for i in range(len(ans)):
    if ans[i] == 'a':
        ans[i] = '0'

if f:
    for a in ans:
        print(a, end="")
    print()
else:
    print('-1')