import numpy as np
N, M = map(int,input().split())
bindings = np.array([list(map(int,input().split())) for i in range(M)])
if M == 0:
    bindings = np.array([[N, 0]])
bindings[:, 0] -= 1

import sys
buf = np.zeros(N, dtype=int) - 1
for s, c in bindings:
    if buf[s] > -1 and buf[s] != c:
        print("-1")
        sys.exit()
    buf[s] = c

if N == 0 and buf[0] == -1:#1桁でゼロ
    print("0")
    sys.exit()
if buf[0] == 0:#最上位がゼロ
    print("-1")
    sys.exit()
    
if buf[0] == -1:#最上位を1にする
    buf[0] = 1
buf[buf == -1] = 0#そのほかはゼロにする

res = "".join(list(map(str, buf)))
print(res)