#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n, m = LI()
    li = LSR(m)
    ans = list('0' * n)
    for i in range(m):
        if int(ans[int(li[i][0][0]) - 1]) == 0:
            ans[int(li[i][0][0]) - 1] = li[i][1][0]
        else:
            ans[int(li[i][0][0]) - 1] = min(li[i][1]
                                            [0], ans[int(li[i][0][0]) - 1])
    if len(''.join(ans)) > 0 and int(ans[0]) != 0:
        print(int(''.join(ans)))
    else:
        print(-1)
    return


# Solve
if __name__ == "__main__":
    solve()
