import sys
from collections import defaultdict

N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]

ll = defaultdict(list)

if N == 1 and M == 0:
    print(0)
    sys.exit()

for s, c in SC:
    ll[s - 1].append(c)
    if s == 1 and c == 0:
        print(-1)
        sys.exit()

ans = 0
for k, v in ll.items():
    if len(v) == 1:
        ans += v[0] * 10**(N - k - 1)
    elif len(list(set(v))) == 1:
        ans += v[0] * 10**(N - k - 1)
    else:
        print(-1)
        sys.exit()

if ans < 10**(N - 1):
    ans += 10**(N - 1)

print(ans)
