#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
void put_double(double obj) { printf("%.12f\n", obj); };
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> s(M);
  vector<int> c(M);
  vector<int> ans(N, -1);
  for (int i = 0; i < (int)(M); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  for (int i = 0; i < (int)(M); i++) {
    if (ans[s[i]] == c[i] || ans[s[i]] == -1)
      ans[s[i]] = c[i];
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (ans[0] == 0) {
    cout << -1 << endl;
    return 0;
  } else if (ans[0] == -1)
    ans[0] = 1;
  for (int i = 0; i < (int)(N); i++) {
    if (ans[i] != -1)
      cout << ans[i];
    else
      cout << 0;
  }
  cout << endl;
}
