/*********      library      *********/
#include <bits/stdc++.h>

/*********      macro      *********/
//rep := for 
#define rep(i,n) for(int i = 0;i < (int)(n);i++)

/*********      namespace      *********/
//std
using namespace std;

int max(int a[],int N);



int main(){
  int N,m;
  cin >> N >> m;

  int s[m],c[m];
  int flg = 0;
  int ans[N];

  rep(i,m){
    cin >> s[i] >> c[i];
    if(s[i] == 1){
      flg++;
    }
  }
  rep(i,N)
    ans[i] = 0;


  if(flg == 0){
    cout << "-1" << endl;
    return 0;
  }

  int lin;

  for(int i = 0;i < N;i++){
    for(int j = 0;j < m;j++){
      if(i + 1 == s[j]){
	lin = c[j];
	if(ans[i] == 0 || ans[i] > lin)
	  ans[i] = lin;
	else
	  continue;
      }
    }
  }
  
  int tmp = 0;

  rep(i,m){
    if(ans[i] != 0)
      tmp++;
  }

  if(tmp == 0){cout << "-1" << endl; return 0;}

  for(int i = 0;i < N;i++){
    cout << ans[i];
  }
  cout << endl;
}

int max(int a[],int N){
  int max = a[0];
  for(int i = 1;i < N;i++){
    (max < a[i]) ? (max = a[i]) : 0;
  }
  return max;
}
