#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  ll n,m;
  cin>>n>>m;
  ll arr[n] = {0};

  vector<ll >v1;
  vector<ll> v2;

  while(m--){
	  ll p,q;
	  cin>>p>>q;
	  v1.push_back(p);
	  v2.push_back(q);
  }

  for(int i=0;i<v1.size();i++){

	  if( v2[i] > 0 ){
		  if(arr[v1[i] - 1]!=0 && v2[i] < arr[v1[i]])
		  arr[v1[i]-1] = v2[i];
		  arr[v1[i]-1] = v2[i];
	  }
  }
  if(arr[0] == 0)
  cout<<"-1";
  else{
  for(int i=0;i<n;i++)cout<<arr[i];
  }
}