#include <bits/stdc++.h>
using namespace std;
void Digvijay() {
  long long n, m;
  cin >> n >> m;
  map<long long, long long> mp;
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    if (x == 1 && y == 0 && n != 1) {
      cout << -1 << "\n";
      return;
    }
    if (mp.count(x) == 0 || mp[x] == y) {
      mp[x] = y;
    } else {
      cout << -1 << "\n";
      return;
    }
  }
  if (mp.count(1) == 0)
    cout << 1;
  else
    cout << mp[1];
  for (long long i = 2; i <= n; i++) {
    cout << mp[i];
  }
  cout << endl;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long _ = 1;
  for (long long __ = 0; __ < _; __++) {
    Digvijay();
  }
}
