N,M = map(int,input().split())
data = {}

for i in range(M):
    s_i,c_i = map(int,input().split())
    if s_i in data and c_i != data[s_i]:
        print(-1)
        exit()
    else:
        data[s_i] = c_i
    if s_i == 1 and c_i == 0:
        print(-1)
        exit()

result = ""
for i in range(3):
    if i+1 in data:
        result += str(data[i+1])
    else:
        result += "0"
print(result)