import sys

n, m = map(int, input().split())
s_c_list = [list(map(int, input().split())) for _ in range(m)]

ans = ["0" for _ in range(n)]

for sc in s_c_list:
    s = sc[0]
    c = sc[1]

    if ans[s-1] == "0":
        ans[s-1] = str(c)
    elif ans[s-1] != str(c):
        print(-1)
        sys.exit()

# ansチェック
if ans[0] == "0":
    print(-1)
else:
    print(int("".join(ans)))