n, m = map(int, input().split())
num = [-1 for _ in range(n + 1)]
for _ in range(m):
    s, c = map(int, input().split())
    if num[s] == -1 or num[s] == c:
        num[s] = c
    else:
        print('-1')
        exit()
if num[1] == -1:
    num [1] = 1
ans = ''
for i in num:
    if i == -1:
        ans += '0'
    else:
        ans += str(i)
print(int(ans) if len(str(int(ans))) == n else '-1')