#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
void V2(T &n, U &m) {
  for (long long int i = 0; i < n.size(); i++) {
    cin >> n[i] >> m[i];
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n, m;
  cin >> n >> m;
  vector<long long int> s(m), c(m);
  V2(s, c);
  map<long long int, long long int> ans;
  for (long long int i = 0; i < (m); ++i) {
    s[i]--;
    if (n != 1 && s[i] == 0 && c[i] == 0) {
      continue;
    }
    if (ans.count(s[i])) {
      ans[s[i]] = min(ans[s[i]], c[i]);
    } else {
      ans[s[i]] = c[i];
    }
  }
  if (ans.count(0)) {
  } else {
    if (n != 1) {
      cout << -1;
      exit(0);
    }
  }
  for (long long int i = 0; i < (n); ++i) {
    if (ans.count(i)) {
      cout << ans[i];
    } else {
      cout << 0;
    }
  }
  cout << endl;
  return 0;
}
