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

int main() {
 int a,b,c,d;
 cin >> a;
 int e[a];
 for(int i=0;i<a;i++) e[i] = 0;
 cin >> b;
 for(int j=0;j<b;j++){
   cin >> c >> d;
   if(e[c]!=0){
     cout << "-1" <, endl;
     return 0;
   }
   e[c] = d;
 }
  if(e[2]!=0) cout << e[2] << e[1] << e[0] << endl;
  else if(e[1]!=0) cout << e[1] << e[0] << endl;
  else cout << e[0] << endl;
}
