def exists(value,n,ms,cs):
    if (len(value) != n):
        return False
    if len(value) < max(ms):
        return False
    if not all([value[i-1] == c for i,c in zip(ms,cs)]:
        return False
    return True
def unzip(li):
    return list(map(list, zip(*li)))
n,m = [int(e) for e in input().split()]
m = [input().split() for e in range(m)]
ms,cs = unzip(m)
ms = [int(e) for e in ms]
result = -1
for i in range(1000):
    if exists(str(i),n,ms,cs):
        result = i
        break
print(result)