#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() {
  long long int n, m;
  cin >> n >> m;
  vector<long long int> a(n, -1);
  long long int f = 0;
  while (m--) {
    long long int s, c;
    cin >> s >> c;
    s--;
    if (n > 1 && s == 0 && c == 0) f++;
    if (a[s] == -1) a[s] = c;
    if (a[s] != -1) {
      if (c == a[s])
        continue;
      else {
        f++;
        break;
      }
    }
  }
  if (f) {
    cout << -1 << endl;
  } else {
    for (long long int i = 0; i < n; i++) {
      if (a[i] == -1)
        cout << 0;
      else
        cout << a[i];
    }
  }
}
