#include <bits/stdc++.h>
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<long long int>;
using vvll = std::vector<std::vector<long long int>>;
using P = std::pair<int, int>;
using vp = std::vector<P>;
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vp sc(m);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    sc[i].first = s;
    sc[i].second = c;
  }
  sort(sc.begin(), sc.end());
  for (int i = 0; i < m - 1; i++) {
    if (sc[i].first == sc[i + 1].first) {
      if (sc[i].second != sc[i + 1].second) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  vi ans(n, 0);
  for (int i = 0; i < m; i++) ans[sc[i].first] = sc[i].second;
  if (ans[0] == 0) {
    if (n == 1) {
      cout << 0 << endl;
      return 0;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) cout << ans[i];
  cout << endl;
}
