n,m = map(int,input().split())
dp = [0]*n
for _ in range(m):
    a, b = (int(x) for x in input().split())
    if dp[a-1] == 0 or dp[a-1] == b:
        dp[a-1] = b
    else:
        print(-1)
        exit()

t = ''.join(map(str, dp))
if t[0] == '0' and 1< n:
    print(-1)
    exit()
else:
    print(t)