def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,M = input_int()

data = []
for i in range(M):
    s,c = input_int()
    data.append([s,c])

output = [0 for i  in range(N)]

def solve(data):
    for d in data:
        if d[1]==0:
            continue
        elif output[d[0]-1]!=0:
            if (output[d[0]-1] != d[1]):
                return -1
            
        output[d[0]-1] = d[1]
    return int("".join(list(map(str, output))))

output = solve(data)
if len(str(output)) != N:
    print(-1)
else:
    print(output)