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チェック
if n > 1 and ans[0] == 0:
    print(-1)
else:
    print("".join(map(str, ans)))