#input
N, M = map(int, input().split())
s = [0] * M
c = [0] * M
for i in range(M):
    s[i], c[i] = map(int, input().split())

#output
from collections import Counter
dp = [-1] * N
for i in range(M):
    if dp[s[i]-1] == -1:
        dp[s[i]-1] = c[i]
    elif c[i] != dp[s[i]-1]:
        print(-1)
        exit()

if dp[0] == -1 or dp[0] == 0:
    print(-1)
else:
    for i in range(N):
        if dp[i] == -1:
            print(0, end = "")
        else:
            print(dp[i], end = "")
