import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, m = map(int, input().split())
    sc = [list(map(int, input().split())) for _ in range(m)]
    
    if n == 1:
        start = 0
        stop = 10
    elif n == 2:
        start = 10
        stop = 100
    else:
        start = 100
        stop = 1000
    
    for i in range(start, stop):
        num = [i for i in str(i)]
        cnt = 0
        for j in range(m):
            if not num[sc[j][0] - 1] == str(sc[j][1]):
                break
            cnt += 1
            if cnt == m:
                print(''.join(num))
                return
    if n == 1 and m == 0:
        print(0)
    else:
        print(-1)
            

if __name__ == '__main__':
    main()