def check(y, conds):
    if len(y) != N:
        return False
    for digit, num in conds.items():
        if y[digit] != num:
            return False
    return True


N, M = map(int, input().split())
conds = {}
for _ in range(M):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
        print(-1)
        exit()
    if s - 1 in conds:
        if conds[s - 1] != str(c):
            print(-1)
            exit()
    else:
        conds[s - 1] = str(c)

for y in range(1000):
    y_str = str(y)
    if check(y_str, conds):
        print(y_str)
        exit()
print(-1)