n,m = map(int,input().split())
ab = []
for _ in range(m):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])

ans = ''

ab.sort()

for i in range(m):
    if ab[i][0] == 1 and ab[i][1] == 0 and n!=1:
        print(-1)
        exit()
    if i == m-1:
        continue
    if ab[i][0] == ab[i+1][0] and ab[i][1] != ab[i+1][1]:
        print(-1)
        exit()
    
dp = [0]*n

for i, j in ab:
    dp[i-1] = j
print(''.join(map(str, dp)))