#include <bits/stdc++.h>
using namespace std;
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  typename vector<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  os << "[";
  typename set<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
  os << "[";
  typename map<F, S>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << it->first << " = " << it->second;
  }
  return os << "]";
}
signed main() {
  int64_t n, m;
  cin >> n >> m;
  vector<int64_t> a(n, -1);
  int64_t f = 0;
  for (int64_t i = 0; i < m; i++) {
    int64_t x, y;
    cin >> x >> y;
    x--;
    if (n > 1 && x == 0 && y == 0) {
      cout << -1;
      return 0;
    }
    if (a[x] == -1 || a[x] == y) {
      a[x] = y;
    } else {
      f++;
      break;
    }
  }
  if (f) {
    cout << -1 << endl;
    return 0;
  }
  for (int64_t i = 0; i < a.size(); i++) {
    if (a[i] == -1) a[i] = 0;
  }
  if (n == 1 && a[0] == 0) {
    cout << 1;
    return 0;
  }
  if (a[0] == 0) a[0] = 1;
  for (auto it : a) cout << it;
}
