N, M = map(int, input().split())
sc = [map(int, input().split()) for _ in range(M)]
s, c = [list(i) for i in zip(*sc)]

def isOK(num):
    l = len(str(num))
    if l != N:
        return False
    for i in range(M):
        if str(num)[s[i]-1] != str(c[i]):
            return False

    return True

ans = -1

for i in range(1000):
    if isOK(i):
        ans = i
        break

print(ans)