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

int main() {
  int n, m; cin >> n >> m;
  int ans[n] = {};
  REP(i, n) --ans[i];
  int s, c;

  REP(i, m) {
    cin >> s >> c;
    if(ans[s-1] == -1 || ans[s-1] == c) {
      ans[s-1] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }

  if(ans[0] == 0) {
    cout << -1 << endl;
    return 0;
  }

  if(n != 1 && ans[0] == -1) ans[0] = 1;
  REP(i, n-1) {
    if(ans[i+1] == -1) ans[i+1] = 0;
  }

  REP(i, n) cout << ans[i];
  cout << endl;

  return 0;
}