N, M = map(int, input().split())
Digit = [0] * 3
Count = 0
for i in range(M):
    s, c = map(int, input().split())
    if Digit[s - 1] == c or Digit[s - 1] == 0:
        Digit[s - 1] = c
        Count += 1
    else:
        print("-1")
        exit()
if Digit[0] == 0:
    if Digit[1] == 0:
        if Digit[2] == 0 and Count == 0:
            print("".join(map(str,Digit)))
            exit()
        else:
            print("-1")
            exit()
    else:
        print("-1")
        exit()
print("".join(map(str,Digit)))