#include <bits/stdc++.h>
using ll = long long int;
using namespace std;
ll mod=1e9+7;

int main(){
  int n,m;
  cin >> n >>m;
  int a[n]={};
  int b[n]={};
  for(int i=0;i<m;i++){
    int q;
    cin >> q;
    q--;
    int p;
    cin >> p;
    b[q]++;
    if(a[q]!=p && b[q]>=2){cout << -1 << endl;
                          return 0;}else{a[q]=p;}
  }
  if(a[0]==0 && n==3 || a[1]==0 && n==2){cout << -1 << endl;
                                                  return 0;}
  cout << 100*a[0]+10*a[1]+a[2] <<endl; 
  
}