import sys

def main():
    line = sys.stdin.readline().rstrip('\n').split()
    N , M = int(line[0]), int(line[1])
    ans = 0

    conditions = {}
    for i in range(M):
        line = sys.stdin.readline().rstrip('\n').split()
        if int(line[0]) not in conditions.keys():
            conditions[int(line[0])] = int(line[1])
        else:
            if conditions[int(line[0])] != int(line[1]):
                print(-1)
                return

    if ((1 in conditions.keys()) and conditions[1]==0 and N!=1):
       print(-1)
       return

    if (1 in conditions.keys()):
        ans += conditions[1]*(10**(N-1))
    else:
        if (N!=1):
            ans += 10**(N-1)

    if (2 in conditions.keys()):
        ans += conditions[2]*(10**(N-2))

    if (3 in conditions.keys()):
        ans += conditions[3]

    print(ans)

main()
