#!/usr/bin/env python3
n,m=map(int,input().split())
ls = [[*map(int,input().split())] for _ in range(m)]
a = [0] * n

for s, c in ls:
    if a[s - 1] in (0, c):
        a[s - 1] = c
    else:
        print(-1)
        exit()
a = int("".join([*map(str, a)]))
if len(str(a)) == n:
    print(a)
else:
    print(-1)
