import itertools
import sys
import math
import numpy as np
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
sys.setrecursionlimit(10**9)

def main():
    N, M = map(int,input().split())

    S = {}
    ans = 0
    for _ in range(M):
        s,c = map(int,input().split())
        if (s == 1 and c == 0) or (s in S.keys() and S[s] != c):
            print(-1)
            exit()

        if not (s in S.keys()):
            ans += c * 10**(N-s)
            S[s] = c

    if not(1 in S.keys()):
        ans += 1 * 10**(N-1)
    print(ans)


if __name__ == "__main__":
  main()
