def judge(restr):
    if restr[0] == 0:
        return False

    return True
    

tmp = list(map(int, input().split(" ")))
N = tmp[0]
M = tmp[1]

restr = [0] * N
init = [0] * N

for i in range(M):
    _tmp = list(map(int, input().split(" ")))
    s = _tmp[0] - 1
    c = _tmp[1]
    if init[s] == 0 or restr[s] > c:
        restr[s] = c
        init[s] += 1

if judge(restr):
    sum = 0
    for i  in range(N):
        sum += restr[i] * (10 ** (N - 1 - i))
    print(sum)
else:
    print(-1)
