#include <bits/stdc++.h>
using namespace std;

int main(){
   int n,m;
   cin >> n >> m;
   int s[m];
   int c[m];
   int ans[m] = {};
   int cub[3] = {10,10,10};
   bool nai = 0;
   
   for(int i=0; i<m; i++){
      cin >> s[i] >> c[i];

      if(ans[s[i]-1]!=c[i] && cub[s[i]-1]!=10) {nai=1;}
      if(n!=1 && s[i]==1 && c[i]==0) nai=1;
      ans[s[i]-1] = c[i];
      cub[s[i]-1] = c[i];
   }
   if(n!=1 && ans[0]==0) ans[0] = 1;

   if(nai){
      cout << "-1" << endl;
   }else{
      for(int i=0; i<m; i++){
         cout << ans[i];
      }
   }
   cout << endl;
   
}
