import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
m = map(int, read().split())
S, C = zip(*zip(m, m))

def main(S, C):
    nums = [-1] * N
    for s, c in zip(S, C):
        s -= 1
        if nums[s] != -1 and nums[s] != c:
            return -1
        nums[s] = c
    if nums[0] == 0:
        return -1
    if nums[0] == -1:
        nums[0] = 1
    for i in range(1, N):
        if nums[i] == -1:
            nums[i] = 0
    return ''.join(map(str, nums))

print(main(S, C))