#include <bits/stdc++.h>
using namespace std;
const int INF = 100100100;
const int MOD = 1e9 + 7;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ;
  int N, M;
  cin >> N >> M;
  vector<int> s(N + 1);
  vector<int> c(N + 1);
  map<int, int> check;
  for (int i = 0; i < (M); i++) {
    cin >> s[i] >> c[i];
    decltype(check)::iterator it = check.find(s[i]);
    if (it != check.end()) {
      if (it->second > c[i]) {
        check.erase(s[i]);
        check.emplace(s[i], c[i]);
      }
    } else {
      check.emplace(s[i], c[i]);
    }
  }
  if (N > 1) {
    decltype(check)::iterator it = check.find(1);
    if (it == check.end() || it->second == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 3; i > N; i--) {
    decltype(check)::iterator it = check.find(i);
    if (it != check.end()) {
      cout << -1 << endl;
      return 0;
    }
  }
  string ans = "";
  for (int i = (1); i < (N + 1); i++) {
    decltype(check)::iterator it = check.find(i);
    if (it != check.end()) {
      ans += to_string(it->second);
    } else {
      ans += "0";
    }
  }
  cout << ans << endl;
}
