#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (m); ++i) cin >> s[i] >> c[i];
  vector<int> val(n, -1);
  for (int i = 0; i < (m); ++i) {
    s[i] -= 1;
    if (val[s[i]] == -1)
      val[s[i]] = c[i];
    else if (val[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (val[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (val[0] == -1) val[0] = 1;
  for (int i = 0; i < (n); ++i) {
    if (val[i] != -1)
      cout << val[i];
    else
      cout << 0;
  }
  cout << endl;
  return 0;
}
