#include <bits/stdc++.h>
using namespace std;
template <typename T>
std::string to_string(const T& n) {
  std::ostringstream stm;
  stm << n;
  return stm.str();
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> ans(N, -1);
  for (int i = 0; i < (int)(M); i++) {
    int s, c;
    cin >> s >> c;
    if (ans[s - 1] == -1)
      ans[s - 1] = c;
    else if (ans[s - 1] == c)
      continue;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (ans[0] == -1) ans[0] = 1;
  if (ans[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (int)(N); i++) {
    if (ans[i] == -1)
      cout << 0;
    else
      cout << ans[i];
  }
  cout << endl;
}
