from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N, M = read_int()
sc = [read_int() for _ in range(M)]

res = [0 for _ in range(N)]

def solve():
    ans = 0
    for s, c in sc:
        if res[s - 1] != 0:
            return -1
        res[s - 1] = c
    if res[0] == 0:
        return -1
    ans = ''.join(str(n) for n in res)
    return int(ans)

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