import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N, M = lr()
    t = [False for _ in range(N)]
    u = ['e' for _ in range(N)]
    for i in range(M):
        s, c = lr()
        if t[s-1] == False or u[s-1] == str(c):
            u[s-1] = str(c)
            t[s-1] = True
        else:
            print(-1)
            return
    ans = ''
    if N == 1 and u[0] == 'e':
        print(0)
        return
    elif N == 2 and u[0] == 'e':
        if u[1] == 'e':
            print(0)
            return
        else:
            print(u[1])
            return
    elif N == 2 and u[0] == '0':
        print(-1)
        return
    elif N == 3 and u[0] == 'e':
        if u[1] == 'e':
            if u[2] == 'e':
                print(0)
                return
            else:
                print(u[2])
                return
        elif u[1] == '0':
            if u[2] == 'e':
                print('100')
            else:
                print('10'+u[2])
        else:
            if u[2] == 'e':
                print(u[1]+'0')
                return
            else:
                print(u[1]+u[2])
                return
    elif N == 3 and u[0] == '0':
        print(-1)
        return
    for i in range(N):
        if u[i] == 'e':
            u[i] = '0'
        ans += u[i]
    print(ans)
resolve()