n, m = (int(i) for i in input().split());

num = [-1 for i in range(n)];

for i in range(m):
    s, c = (int(i) for i in input().split());
    s -= 1;
    if num[s] > -1 and num[s] != c:
        print('-1');
        exit(0);
    num[s] = c;

if num[0] == 0:
    print('-1');
    exit(0);

for i in range(n):
    print(max(num[i], int(i == 0)), end="");
