nm = input().split(' ');
n = int(nm[0]);
m = int(nm[1]);

ans = [0]*n;
check = 1;

for i in range(m) :
    sc = input().split(' ');
    s = int(sc[0]);
    c = int(sc[1]);
    if s == 1 and c == 0 and n > 1:
        check = 0;
    elif n > 1 and ans[s-1] > 0 and (not(ans[s-1] == c)) :
        check = 0;
    elif n == 1 and (not(ans[s-1] == c)) :
        check = 0;
    else :
        ans[s-1] = c;

if ans[0] == 0 :
    ans[0] = 1;

if check :
    for i in range(n) :
        print(ans[i], end="");
    print();
else :
    print(-1);
