import numpy as np
def getLine():
    return list(map(int, input().split()))
n,m = getLine()
r = np.full(n,-1,dtype=int)
for i in range(m):
    a,b = getLine()
    
    if r[a - 1] == -1:
        r[a - 1] = b
    elif r[a - 1] != b:
        print(-1)
        break
else:
    if (n > 1 and r[0] <= 0) or (n == 1 and r[0] < 0):
        print(-1)
    elif r[0] == 0:
        print('0')
    else:
        r[r == -1] = 0
        r = r.astype(str)
        print(''.join(r))