#include <bits/stdc++.h>
using namespace std;
template <typename T>
std::ostream &operator<<(std::ostream &out, vector<T> &v) {
  for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
    out << v[i] << " ";
  out << "\n";
  return out;
}
template <typename T, typename N>
std::ostream &operator<<(std::ostream &out, vector<pair<T, N> > &v) {
  for (size_t i = 0; i < v.size(); ++i)
    out << "(" << v[i].first << ", " << v[i].second << ") ";
  out << "\n";
  return out;
}
template <typename T>
std::ostream &operator<<(std::ostream &out, vector<vector<T> > &v) {
  for (size_t i = 0; i < v.size(); ++i) {
    for (size_t j = 0; j < v[i].size(); ++j) {
      out << v[i][j] << " ";
    }
    out << "\n";
  }
  return out;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  string ans(n, '.');
  int s, c;
  for (int i = 0; i < m; ++i) {
    cin >> s >> c;
    --s;
    if (ans[s] != '.' && c != ans[s] - '0') {
      cout << "-1\n";
      return 0;
    }
    ans[s] = c + '0';
  }
  if (n == 1 && !m) {
    cout << "1\n";
    return 0;
  }
  int actual = 0;
  for (int i = 0; i < n; ++i) {
    if (ans[i] != '.') {
      ++actual;
    }
  }
  if (actual < n) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < 10; ++j) {
        if (ans[i] == '.') {
          if (j == 0 && i == 0) {
            continue;
          }
          ans[i] = j + '0';
        }
      }
    }
  }
  if (ans[0] == '0' && n > 1) {
    cout << "-1\n";
  } else {
    cout << ans << "\n";
  }
  return 0;
}
