n, m = map(int, input().split())
s = []
for _ in range(n):
    s.append([int(x) for x in input().split()])
res = ["0"]*n
for i in range(n):
    if s[i][0] == 1 and s[i][1] == 0:
        print('-1')
        break
    res[s[i][0]-1] = str(s[i][1])
print("".join(res))