#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);
  for (int i = 0; i < (m); ++i) {
    for (int j = 0; j < (m); ++j) {
      if (i == j) continue;
      if (s.at(i) == s.at(j) and c.at(i) != c.at(j)) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  if (n == 2 or n == 3) {
    for (int i = 0; i < (m); ++i) {
      if (s.at(i) == 1 and c.at(i) == 0) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  vector<int> ans(n, 0);
  for (int i = 0; i < (m); ++i) {
    ans.at(s.at(i) - 1) = c.at(i);
  }
  if (ans.at(0) == 0 and n == 1)
    cout << "0";
  else if (ans.at(0) == 0)
    ans.at(0) = 1;
  for (int i = 0; i < (n); ++i) cout << ans.at(i);
  cout << endl;
  return 0;
}
