import sys

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

ans = [0] * n

for s, c in s_c_list:
    if ans[s-1] == 0:
        ans[s-1] = c
    else:
        print(-1)
        sys.exit()

# ansチェック
ans = "".join(map(str,ans))

if ans == "0" or (m == 0 and n == 1):
    print(0)
elif ans[0] == "0":
    print(-1)
else:
    print(ans)