import math

n,m = map(int, input().rstrip().split())

value = 0
s = [-1] * n

for i in range(m) :
    si,ci = map(int,input().rstrip().split())
    if s[si-1] == -1 :
        s[si-1] = ci
    elif s[si-1] != ci :
        value = -1
        break
    else :
        continue

if s[0] == 0 :
    value = -1
if s[0] == -1 :
    s[0] = 1
for i in range(n) :
    if s[i] == -1 :
        s[i] = 0 
if value != -1 :
    for i in range(n) :
        value = value * 10 + s[i] 
print(value)