#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T>
void pv(vector<T> vec) {
  cout << "[";
  for (auto& v : vec) {
    cout << v << ",";
  }
  cout << "]" << endl;
}
template <>
void pv(vector<P> vec) {
  cout << "[";
  for (auto& v : vec) {
    cout << "<" << v.first << "," << v.second << ">"
         << ",";
  }
  cout << "]" << endl;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m, 0);
  vector<int> c(m, 0);
  for (int i = 0; i < (m); ++i) cin >> s.at(i) >> c.at(i);
  bool out = false;
  vector<int> ans(n, 0);
  for (int i = 0; i < (m); ++i) {
    if (ans.at(s.at(i) - 1)) {
      if (ans.at(s.at(i) - 1) != c.at(i)) {
        out = true;
        break;
      }
    } else {
      ans.at(s.at(i) - 1) = c.at(i);
    }
  }
  if (out)
    cout << "-1";
  else if (!ans.at(0))
    cout << "-1";
  else {
    for (int i = 0; i < (n); ++i) cout << ans.at(i);
  }
  cout << endl;
  return 0;
}
