#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
  }
  string tmp[n];
  for (int i = 0; i < m; ++i) {
    tmp[s[i] - 1] = to_string(c[i]);
  }
  if (tmp[0] == "" && tmp[n] == "") {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    if (tmp[i] == "") {
      tmp[i] = to_string(0);
    }
  }
  if (tmp[0] == "0") {
    cout << -1 << endl;
    return 0;
  }
  int ans = atoi(tmp[0].c_str()) * 100 + atoi(tmp[1].c_str()) * 10 +
            atoi(tmp[2].c_str());
  cout << ans << endl;
  return 0;
}
