#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void _err(std::ostream& cerr, istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void _err(std::ostream& cerr, istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "  ";
  _err(cerr, ++it, args...);
}
const double pi = 2 * acos(.0);
const int inf = 0x3f3f3f3f;
const ll mod = (ll)(1e9) + 7;
const double eps = 1e-10;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
  std::fill((T*)array, (T*)(array + N), val);
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T> V) {
  os << "[";
  int cnt = 0;
  T curr;
  if (!V.empty()) {
    for (int i = 0; i < V.size() - 1; ++i) {
      if (V[i] == curr)
        cnt++;
      else
        cnt = 0;
      if (cnt == 4) os << "... ";
      if (cnt < 4) os << V[i] << " ";
      curr = V[i];
    }
    os << V.back();
  }
  os << "]";
  return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U> P) {
  os << "(";
  os << P.first << "," << P.second;
  os << ")";
  return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, const set<T, U> V) {
  os << "{";
  if (!V.empty()) {
    auto it = V.begin();
    for (int i = 0; i < V.size() - 1; ++i) {
      os << *it << " ";
      it++;
    }
    os << *it;
  }
  os << "}";
  return os;
}
template <typename K, typename H, typename P>
ostream& operator<<(ostream& os, const unordered_set<K, H, P> V) {
  os << "{";
  if (!V.empty()) {
    auto it = V.begin();
    for (int i = 0; i < V.size() - 1; ++i) {
      os << *it << " ";
      it++;
    }
    os << *it;
  }
  os << "}";
  return os;
}
template <typename K, typename C>
ostream& operator<<(ostream& os, const multiset<K, C> V) {
  os << "{";
  if (!V.empty()) {
    auto it = V.begin();
    for (int i = 0; i < V.size() - 1; ++i) {
      os << *it << " ";
      it++;
    }
    os << *it;
  }
  os << "}";
  return os;
}
template <typename K, typename T, typename C>
ostream& operator<<(ostream& os, const map<K, T, C> V) {
  os << "{";
  if (!V.empty()) {
    auto it = V.begin();
    for (int i = 0; i < V.size() - 1; ++i) {
      os << "(";
      os << it->first << "," << it->second;
      os << ") ";
      it++;
    }
    os << "(";
    os << it->first << "," << it->second;
    os << ")";
  }
  os << "}";
  return os;
}
template <typename K, typename T, typename C>
ostream& operator<<(ostream& os, const unordered_map<K, T, C> V) {
  os << "{";
  if (!V.empty()) {
    auto it = V.begin();
    for (int i = 0; i < V.size() - 1; ++i) {
      os << "(";
      os << it->first << "," << it->second;
      os << ") ";
      it++;
    }
    os << "(";
    os << it->first << "," << it->second;
    os << ")";
  }
  os << "}";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const deque<T> V) {
  os << "[";
  if (!V.empty()) {
    for (int i = 0; i < V.size() - 1; ++i) {
      os << V[i] << "->";
    }
    if (!V.empty()) os << V.back();
  }
  os << "]";
  return os;
};
template <typename T, typename Cont, typename Comp>
ostream& operator<<(ostream& os, const priority_queue<T, Cont, Comp> V) {
  priority_queue<T, Cont, Comp> _V = V;
  os << "[";
  if (!_V.empty()) {
    while (_V.size() > 1) {
      os << _V.top() << "->";
      _V.pop();
    }
    os << _V.top();
  }
  os << "]";
  return os;
};
struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2>& p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
template <class T>
void Chmod(T& a, const T& m) {
  a = ((((a) % (m)) + (m)) % (m));
}
template <class T>
bool Chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool Chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
class CGuessTheNumber {
 public:
  void solve(std::istream& cin, std::ostream& cout, std::ostream& cerr) {
    int N, M;
    cin >> N >> M;
    vector<int> v(N, -1);
    for (__typeof(M) i = 0, _len = (M); i < (_len); i += 1) {
      int s, c;
      cin >> s >> c;
      s--;
      if (~v[s] && v[s] != c) do {
          cout << (-1) << endl;
          return;
        } while (false);
      v[s] = c;
    }
    if (N == 1) do {
        cout << (v[0]) << endl;
        return;
      } while (false);
    if (v[0] == 0) do {
        cout << (-1) << endl;
        return;
      } while (false);
    if (~v[0])
      cout << v[0];
    else
      cout << 1;
    for (__typeof(N - 1) i = 0, _len = (N - 1); i < (_len); i += 1)
      if (~v[i + 1])
        cout << v[i + 1];
      else
        cout << 0;
  }
};
int main() {
  CGuessTheNumber solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  std::ostringstream err;
  in.tie(0);
  ios::sync_with_stdio(0);
  solver.solve(in, out, err);
  return 0;
}
