hashmap = {}
N, M = map(int,input().split()) 
P = [list(map(int,input().split())) for i in range(M)]

# N, M = 3, 1
# P = [[1,0]]

def func():
    for l in P:
        if l[0] in hashmap and hashmap[l[0]]!=l[1]:
            return -1
        else:
            hashmap[l[0]]=l[1]

    ans = ""
    if 1 not in hashmap:
        ans+="1"
    else:
        ans+=str(hashmap[1])

    for i in range(2,N+1):
        if i not in hashmap:
            ans+="0"
        else:
            ans+=str(hashmap[i])
    if int(ans)==0:
        return -1
    return int(ans)
  
print(func())