#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
inline string toString(const T& a) {
  ostringstream oss;
  oss << a;
  return oss.str();
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  os << "{ ";
  for (int i = (0); i < (vec.size()); i++)
    os << ((i == 0) ? "" : ", ") << i << ":" << vec[i];
  os << " }";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, vector<vector<T>>& vec) {
  os << "{" << endl;
  for (int i = (0); i < (vec.size()); i++)
    os << "\t   " << i << ":" << vec[i] << ((i == vec.size() - 1) ? "" : ",")
       << endl;
  os << "\t }";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, set<T>& p) {
  os << "{ ";
  for (auto itr = (p).begin(); itr != (p).end(); itr++)
    os << ((itr == p.begin()) ? "" : ", ") << *itr;
  os << " }";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, queue<T>& p) {
  queue<T> q(p);
  os << "[< " << (q.empty() ? " <]" : "");
  while (!q.empty()) {
    os << q.front();
    q.pop();
    os << (q.empty() ? " <]" : ", ");
  }
  return os;
}
template <class T>
ostream& operator<<(ostream& os, priority_queue<T>& p) {
  priority_queue<T> q(p);
  os << "[< " << (q.empty() ? " <]" : "");
  while (!q.empty()) {
    os << q.top();
    q.pop();
    os << (q.empty() ? " <]" : ", ");
  }
  return os;
}
template <class T, class U>
ostream& operator<<(ostream& os, pair<T, U>& p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <class T, class U>
ostream& operator<<(ostream& os, map<T, U>& p) {
  os << "{ ";
  for (auto itr = (p).begin(); itr != (p).end(); itr++)
    os << ((itr == p.begin()) ? "" : ", ") << itr->first << ":" << itr->second;
  os << " }";
  return os;
}
void dump_f(string& nm, char t) { cerr << endl; }
template <class T, class... Ts>
void dump_f(string& nm, char t, T&& x, Ts&&... ts) {
  int l = nm.find_first_of(',');
  string name(nm, 0, l), nx(nm, l + 1, -1);
  if (t == '\n')
    cerr << "  " << name << "\t: " << x << t;
  else
    cerr << name << ": " << x << "," << t;
  dump_f(nx, t, forward<Ts>(ts)...);
}
template <class... Ts>
void dump_m(int&& ln, string&& nm, char t, Ts&&... ts) {
  cerr << "[ln: " << ln << "]" << t;
  dump_f(nm, t, forward<Ts>(ts)...);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<int> X(N, -1);
  int s, c;
  bool is = true;
  if (M != 0) {
    vector<int> S(M, 0), C(M, 0);
    for (int i = (0); i < (M); i++) cin >> S[i] >> C[i];
    for (int i = (0); i < (M); i++) {
      S[i]--;
      if (X[S[i]] == -1 || X[S[i]] == C[i])
        X[S[i]] = C[i];
      else {
        is = false;
      }
    }
    if (X[0] == 0) is = false;
  }
  if (is) {
    if (N == 1 && X[0] == -1)
      cout << 0;
    else {
      for (int i = (0); i < (N); i++) {
        if (X[i] == -1) X[i] = (i == 0) ? 1 : 0;
        cout << X[i];
      }
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return (0);
}
