from collections import defaultdict
d = defaultdict(list)

N, M = map(int, input().split())
for _ in range(M):
    s, c = map(int, input().split())
    d[s].append(c)

ans = [-1] * N

# とりあえず桁を確定させる
for k, v in d.items():
    if len(set(v)) > 1:
        print(-1)
        exit()
    ans[k - 1] = v[0]

if N == 1:
    val = ans.pop()
    val = max(0, val)
else:
    val = ""
    for i, a in enumerate(ans):
        if a != -1:
            val += str(a)
        else:
            if i == 0:
                val += "1"
            else:
                val += "0"

if val[0] == "0":
    print(-1)
    exit()

print(val)
