n, m = map(int, input().split())
scList = [list(map(int, input().split())) for _ in range(m)]
num = ["-" for _ in range(n)]
flag = True
for i in range(m):
    s = scList[i][0] - 1
    c = scList[i][1]
    if (num[s] != "-" and num[s] != str(c)) or (s == 0 and c == 0):
        flag = False
        break
    num[s] = str(c)
if not flag:
    print("-1")
else:
    ans = "".join(num)
    if ans[0] == "0":
        ans = "1" + ans[1:]
    print(ans.replace("-", "0"))
