import sys
N, M = map(int, input().split())
s = {}
ans = 0

for _ in range(M):
    si, ci = map(int, input().split())
    if si in s.keys():
        if ci != s[si]:
            print(-1)
            sys.exit()
        else:
            continue
    s[si] = ci
    ans += ci * 10**(N-si)

if len(str(ans)) == N:
    print(ans)
else:
    print(-1)
