#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<P> v(m);
  for (int i = 0; i < (m); i++) cin >> v[i].first >> v[i].second;
  for (int i = 0; i < (m); i++) v[i].first--;
  vector<int> ans(4, -1);
  for (int i = 0; i < (m); i++) {
    ans[v[i].first] = max(ans[v[i].first], v[i].second);
  }
  int minusnokazu = 0;
  for (int i = 0; i < (n); i++) {
    if (ans[i] == -1) minusnokazu += 1;
  }
  if (minusnokazu > 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (n); i++) {
    if (ans[i] != -1) {
      cout << ans[i];
    } else {
      cout << 0;
    }
  }
  return 0;
}
