#!/usr/bin/env python
from collections import deque, defaultdict
import bisect
from math import factorial

def main():
    N, M = map(int, input().split())
    sc_list = []
    for _ in range(M):
        s, c = map(int, input().split())
        sc_list.append((s, c))

    for i in range(1000):
        st = str(i)
        st = " " * (N - len(st)) + st
        if all([st[s-1] == str(c) for s, c in sc_list]):
            print(int(i))
            return
    print(-1)


if __name__ == '__main__':
    main()
