N, M = map(int, input().split())
possible_num = ["X"] * N
memo = [-1]*N
ans = ""

for _ in range(M):
    si, ci = input().split()
    si = int(si)
    if memo[si-1] != -1 and memo[si-1] != ci:
        print(-1)
        quit()
    memo[si-1] = ci
    possible_num[si-1] = ci

if possible_num[0] == "0":
    print(-1)
    quit()
elif possible_num[0] == "X":
    possible_num[0] = "1"

for item in possible_num:
    if item == "X":
        item = 0
    ans += str(item)

print(int(ans))
