#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  int n, m;
  cin >> n >> m;
  vector<int> a(n, 0);
  vector<int> used(n, 0);
  a[0] = 1;
  vector<pair<int, int> > q(m);
  for (int i = 0; i < m; i++) {
    cin >> q[i].first >> q[i].second;
  }
  for (int i = 0; i < m; i++) {
    if (used[q[i].first - 1] && q[i].second != a[q[i].first - 1]) {
      cout << -1 << endl;
      return 0;
    } else {
      a[q[i].first - 1] = q[i].second;
      used[q[i].first - 1] = 1;
    }
  }
  if (a[0] == 0 && n > 1) cout << -1 << endl;
  if (n == 1 && m == 0)
    cout << 0 << endl;
  else {
    for (int i = 0; i < n; i++) {
      cout << a[i];
    }
    cout << endl;
  }
  cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}
