from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
data = []
for i in range(M):
    s,c = [int(x) for x in stdin.readline().rstrip().split()]
    data.append((s,c))
ans = ["0"]*(N)

for i,j in sorted(data)[::-1]:
    ans[i-1] = str(j)

if ans[0] == "0":
    print(-1)
else:
    print("".join(ans))