#include <bits/stdc++.h>
using namespace std;
void yes() {
  cout << "Yes" << endl;
  return;
}
void 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];
    if (n != 1 && s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return;
    }
  }
  vector<pair<int, int> > data(m);
  for (int(i) = 0; (i) < (m); (i)++) data[i] = make_pair(s[i], c[i]);
  stable_sort((data.begin()), (data.end()));
  for (int(i) = 0; (i) < (m - 1); (i)++) {
    if (data[i].first == data[i + 1].first &&
        data[i].second != data[i + 1].second) {
      cout << -1 << endl;
      return;
    }
  }
  vector<int> ans(n, 0);
  for (int(i) = 0; (i) < (m); (i)++) {
    ans[s[i] - 1] = c[i];
  }
  if (n != 1 && ans[n - 1] == 0) ans[n - 1] = 1;
  for (int(i) = 0; (i) < (n); (i)++) cout << ans[i];
  cout << endl;
  return;
}
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}
