N, M = map(int, input().split())

s_c_dict = {}

exit = 0
for i in range(M):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
        print("-1")
        exit= 1
        break
    if s in s_c_dict and s_c_dict[s] != c:
        print("-1")
        exit=1
        break

    s_c_dict[s] = c

ans = 0

if exit != 1:
    for i in range(N, 0, -1):
        # print(i)
        if N-i+1 in s_c_dict:
            ans += 10**(i-1) * s_c_dict[N-i+1]
        elif i == N:
            ans += 10 ** i * 1
    print(ans)