#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n, m = LI()
    sc = LIR(m)
    ans = [0] * n
    ans[0] = 1
    c = [0] * n
    for s, ci in sc:
        s -= 1
        if s == 0 and ci == 0 and n == 1:
            print(-1)
            return
        if c[s]:
            if ans[s] == ci:
                continue
            else:
                print(-1)
                return
        else:
            c[s] = 1
            ans[s] = ci
    l = []
    for i in range(n):
        if c[i]:
            if ans[i] == 0 and i == 0:
                if n == 1:
                    l.append("0")
                else:
                    print(-1)
                    return
            else:
                l.append(str(ans[i]))
        else:
            l.append(str(ans[i]))
    print("".join(l))
    return


#main
if __name__ == '__main__':
    solve()
