
n, m = map(int, input().split())
num = [None] * n
br = False
for i in range(m):
    s, c = map(int, input().split())
    if num[s-1] is not None and num[s-1] != c:
        br = True
        continue
    num[s-1] = c
if br:
    print(-1)
else:
    for i, a in enumerate(num):
        if a is None:
            num[i] = 0
    t = int("".join(map(str, num)))
    if len(str(t)) != n:
        print(-1)
    else:
        print(t)