# -*- coding: utf-8 -*-
N, M = map(int, input().split())
ans_list = ["X"] * N
for i in range(M):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
        print(-1)
        break
    elif ans_list[s - 1] == "X" or ans_list[s - 1] == c:
        ans_list[s - 1] = c
    else:
        print(-1)
        break
else:
    ans_list = ["0" if i == "X" else str(i) for i in ans_list]
    print(int("".join(ans_list)))
