n, m = [int(i) for i in input().split(" ")]

ng = False
s_dict = {}
for i in range(m):
    s, c = [int(i) for i in input().split(" ")]
    if s == 1 and c == 0:
        ng = True
        break
    if s in s_dict:
        if s_dict[s] != c:
            ng = True
            break
    s_dict[s] = c

if ng:
    print(-1)
    exit(0)
    
num = 0
    
if 1 < n and (1 not in s_dict):
    num += pow(10, n - 1) * 1
for k, v in s_dict.items():
    num += pow(10, n - k) * v

print(num)