#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename KeyType, typename ValueType>
std::pair<KeyType, ValueType> get_max(const std::map<KeyType, ValueType>& x) {
  using pairtype = std::pair<KeyType, ValueType>;
  return *std::max_element(x.begin(), x.end(),
                           [](const pairtype& p1, const pairtype& p2) {
                             return p1.second < p2.second;
                           });
}
using namespace std;
using P = pair<int, int>;
using ll = long long;
const ll INF = 1LL << 60;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n);
  for (int i = 0; i < (n); ++i) s[i] = -1;
  for (int i = 0; i < (m); ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    if (s[a] != -1 && s[a] != b) {
      cout << -1 << endl;
      return 0;
    }
    s[a] = b;
  }
  for (int i = 0; i < (n); ++i) {
    if (s[i] == -1) s[i] = 0;
  }
  if (s[0] == 0) {
    cout << -1 << endl;
    return 0;
  } else {
    for (int i = 0; i < n; i++) {
      cout << s[i];
    }
    cout << endl;
  }
  return 0;
}
