N, M = tuple(map(int, (input().split())))

lst = []
for i in range(M):
    lst.append(tuple(map(int, (input().split()))))

# print(N,M)
# print(lst)

class Number():
    def __init__(self, N):
        self.ketasu = N
        self.number = ["#" for x in range(N)]
        self.result = 0

    def definition(self, keta, n):
        if self.check(keta, n):
            self.number[keta-1]= n
        else:
            self.result = -1

    def check(self, keta, n):
        if keta == 1 and n == 0:      # 最大桁が0のとき
            return False
        if self.number[keta-1] != "#":     # 同じ桁が更新されたとき
            return self.number[keta-1] == n
        else:
            return True

    def minimize(self):
        if self.result == -1:
            return self.result
        else:
            for i, ch in enumerate(self.number):
                if ch == "#":
                    if i == 0:
                        self.number[i] = 1
                    else:
                        self.number[i] = 0
                self.result += self.number[i] * 10 ** (self.ketasu-i-1)
            return self.result

num = Number(N)
for hint in lst:
    num.definition(hint[0], hint[1])
# print(num.number)
print(num.minimize())
