# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N,M = map(int,input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]

    res = -1

    if N == 1:
        start = 0
        end = 10
    elif N == 2:
        start = 10
        end = 100
    elif N == 3:
        start = 100
        end = 1000

    for i in range(start,end):
        now = str(i)
        count = 0
        for j in range(M):
            index = sc[j][0]-1
            temp = str(sc[j][1])
            if now[index] == temp:
                count += 1
            else:
                break
            if count == M:
                res = i
        if res != -1:
            break

    print(res)



main()
