n, m = map(int, input().split())
digits = [-1]*3
for _ in range(m):
    s, c = map(int, input().split())
    s -= 1
    if digits[s] == -1 or digits[s] == c:
        digits[s] = c
    else:
        print(-1)
        break
else:
    if n > 1 and digits[0] == 0:
        print(-1)
    else:
        ans = ''
        for i, d in enumerate(digits):
            if i == 0 and d == -1:
                ans += '1'
            elif i > 0 and d == -1:
                ans += '0'
            else:
                ans += str(d)
        print(ans)