N, M = map(int, input().split())
from collections import defaultdict
def hoge():
    return "0"

d = defaultdict(hoge)

for i in range(M):
    s, c = input().split()
    s = int(s)
    if s == 1 and c == "0":
        print(-1)
        exit()
    if s in d.keys():
        if d[s] != c:
            print(-1)
            exit()
    else:
        d[s] = c
ans = []
if d[1] == "0":
    ans.append("1")
else:
    ans.append(d[1])
for i in range(2, N + 1):
    ans.append(d[i])
print("".join(ans))