n, m = map(int, input().split())
s, c = [], []
for i in range(m):
    a, b = map(int, input().split())
    s.append(a), c.append(b)
    
ans = [0, 0, 0]
for i in range(m):
    if ans[s[i] - 1] == 0 or ans[s[i] - 1] == c[i]:
        ans[s[i] - 1] = c[i]
    else:
        print('-1')
        break

    if i == m - 1:
        if ans[0] * 100 + ans[1] * 10 + ans[2] >= 10 ** (n - 1):
            print(''.join(map(str, ans)))

        else:
            print('-1')
        
