#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;
    }
  }
  bool first_flag = true;
  for (int i = 0; i < (int)(M); i++) {
    if (ans[i] == -1) {
      if (first_flag) {
        cout << 1;
        first_flag = false;
      } else
        cout << 0;
    } else {
      if (first_flag && ans[i] == 0) {
        cout << -1 << endl;
        return 0;
      }
      cout << ans[i];
      first_flag = false;
    }
  }
  cout << endl;
}
