#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  int res = 0;
  vector<int> a(n);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (a[s - 1] == 0 || a[s - 1] == c) {
      a[s - 1] = c;
    } else {
      cout << -1 << endl;
      ;
      return 0;
    }
  }
  if (a[0] == 0 && n > 1) {
    cout << -1 << endl;
    ;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cout << a[i];
    ;
  }
  cout << "" << endl;
  ;
}
