# -*- coding: utf-8 -*-

def solve():
    N,M = map(int,input().split())
    D = dict()
    for _ in range(M):
        s,c = map(int,input().split())
        if s in D and D[s] != c:
            return '-1'
        else:
            D[s] = c

    if N>1 and 1 in D and D[1] == 0:
        return '-1'

    if 1 not in D:
        D[1] = 1

    if 2 not in D:
        D[2] = 0

    if 3 not in D:
        D[3] = 0

    res = sum(D[i+1]*10**(N-i-1) for i in range(N))

    return str(res)

if __name__ == '__main__':
    print(solve())

