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

def solve():
    N,M = map(int,input().split())
    D = dict()
    for _ in range(M):
        s,c = map(int,input().split())
        D[s] = D.get(s,set()) | {c,}

    if not all(len(v)==1 for v in D.values()):
        return '-1'

    if N>1 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].pop()*10**(N-i-1) for i in range(N))

    return str(res)

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

