# ACB157 C

n, m = map(int, input().split())
res = ["0"] * n

for i in range(m):
    s, c = map(int, input().split())
    
    # 同じ桁で条件が違う場合はNG
    if res[s-1] != "0" and res[s-1] != str(c):
        res = -1
        break
    # 1桁目に0を指定する場合はNG
    elif s == 1 and c == 0:
        res = -1
        break
    else:
        res[s-1] = str(c)

if res == -1:
    print(res)
else:
    if res[0] == "0":
        res[0] = "1"
    print(int("".join(res)))