#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
ostream& operator<<(ostream& s, const complex<T>& d) {
  return s << "(" << d.real() << ", " << d.imag() << ")";
}
template <typename T1, typename T2>
ostream& operator<<(ostream& s, const pair<T1, T2>& d) {
  return s << "(" << d.first << ", " << d.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& d) {
  int len = d.size();
  for (long long i = 0; i < len; i++) {
    s << d[i];
    if (i < len - 1) s << " ";
  }
  return s;
}
template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& d) {
  int len = d.size();
  for (long long i = 0; i < len; i++) {
    s << d[i] << "\n";
  }
  return s;
}
template <typename T>
ostream& operator<<(ostream& s, const set<T>& v) {
  s << "{ ";
  for (auto itr = v.begin(); itr != v.end(); ++itr) {
    if (itr != v.begin()) {
      s << ", ";
    }
    s << (*itr);
  }
  s << " }";
  return s;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& s, const map<T1, T2>& m) {
  s << "{"
    << "\n";
  for (auto itr = m.begin(); itr != m.end(); ++itr) {
    s << " " << (*itr).first << " : " << (*itr).second << "\n";
  }
  s << "}"
    << "\n";
  return s;
}
const long long mod = 1e9 + 7;
const long long inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
const double EPS = 1e-10;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> cnt(n + 1, -1);
  bool flag = true;
  for (long long i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (cnt[s] == -1) {
      cnt[s] = c;
    } else {
      if (cnt[s] != c) {
        flag = false;
      }
    }
  }
  if (cnt[1] == -1) flag = false;
  if (n != 1 && cnt[1] == 0) flag = false;
  if (!flag)
    cout << -1 << "\n";
  else {
    for (long long i = 1; i < n + 1; i++) {
      if (cnt[i] == -1)
        cout << 0;
      else
        cout << cnt[i];
    }
    cout << "\n";
  }
}
