#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<P> sc(m);
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    sc[i] = (P(s, c));
  }
  vector<int> ans(n);
  for (int i = 0; i < (int)(m); i++) {
    int index = sc[i].first - 1;
    if ((ans[index] != 0 && ans[index] != sc[i].second) ||
        (n != 1 && index == 0 && sc[i].second == 0)) {
      cout << -1 << endl;
      return 0;
    }
    ans[index] = sc[i].second;
  }
  if (n == 1) {
    cout << ans[0] << endl;
    return 0;
  }
  bool noZero = true;
  int i = 0;
  while (noZero) {
    if (ans[i] != 0)
      noZero = false;
    else
      ++i;
  }
  for (int a = i; a < n; ++a) cout << ans[a];
  cout << endl;
}
