#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

int main(){
  int N, M;
  cin >> N >> M;
  bool judge1 = 0, judge2 = 0;
  vector<int> s(N);
  rep(i, M){
    int a, b;
    cin >> a >> b;
    s[a-1] = b;
    if a == 1; judge1 = 1;
    if a == N; judge2 = 1;
  }
  
  if (judge1 && judge2){
    rep(i, N){
      cout << s[i];
    }
    cout << endl;
  }
  
  else {
    cout << -1 << endl;
  }
    
  
}