# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy
import bisect


def dfs(s, prev, pre):
  val[s] += Ope[s] + prev
  for i in G[s]:
    if(i == pre):
      continue
    dfs(i, val[s], s)

#X = str(input()).split()
#a = [int(x) for x in input().split()]
#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())

N, M = map(int, input().split())
s= []
c= []

n = [0]*N

ans = 0

for i in range(M):
  sc = str(input()).split()
  s.append(int(sc[0]))
  c.append(int(sc[1]))
  n[s[i]-1] = c[i]

#map(str, n)
ans = "".join(map(str,n))


for i in range(M):
 for j in range(M):
  if(s[i]==s[j]):
    if(c[i]!=c[j]):
      ans =-1
  if(c[i]==0):
    if(N!=1):
      ans = -1

if(ans == -1):
  print(-1)
else:
  if(N==1 and n[0]==0):
    print(0)
  else:
    if(n[0]==0):
      n[0]=1
    ans = "".join(map(str,n))
    print(ans)


