def solve(dic, n, bad):
    if bad:
        return -1

    li = [-1]*n
    for k, v in dic.items():
        li[k-1] = v

    if n==1:
        if li[0] == -1: ## unset
            return 0
        else: ## li is obviously set by dictionary
            st = map(str, li)
            return int(''.join(st))

    else:
        if li[0] == 0:
            ## well not possible for a n digit number
            return -1
        if li[0] == -1:
            ## unset; so take any one one digit
            li[0] = 1
            for i in range(1, n):
                if li[i] == -1:
                    li[i] = 0

            st = map(str, li)
            return int(''.join(st))
        else:
            for i in range(1, n):
                if li[i] == -1:
                    li[i] = 0
            st = map(str, li)
            return int(''.join(st))
        

n, m = map(int, input().split())

dic = {}
bad = False
for i in range(m):
    s, c = map(int, input().split())
    if dic.get(s, -1)==-1:
        dic[s] = c
    else:
        bad = True

print(solve(dic, n, bad))
