import numpy as np

n, m = list(map(int, input().split(' ')))
s = [list(map(int, input().split(' ')))
     for _ in range(m)]
s = np.array(s)

comps = [0 for _ in range(n)]

output = 0
for _s in s:
    if comps[_s[0] - 1] == 0:
        output += 10**(n-_s[0]) * _s[1]
        comps[_s[0] - 1] = 1
    else:
        if _s[1] != output//10**(n-_s[0]):
            output = -1

if output == 0:
    output = -1

print(output)