#include <bits/stdc++.h>
using namespace std;
template <class T>
using VV = vector<vector<T>>;
template <class T>
inline T SMIN(T& a, const T b) {
  return a = (a > b) ? b : a;
}
template <class T>
inline T SMAX(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <class Iter>
void __kumaerrc(Iter begin, Iter end) {
  for (; begin != end; ++begin) {
    cerr << *begin << ',';
  }
  cerr << endl;
}
void __kumaerr(istream_iterator<string> it) {
  (void)it;
  cerr << endl;
}
template <typename T, typename... Args>
void __kumaerr(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << "=" << a << ", ", __kumaerr(++it, args...);
}
template <typename S, typename T>
std::ostream& operator<<(std::ostream& _os, const std::pair<S, T>& _p) {
  return _os << "{" << _p.first << ',' << _p.second << "}";
}
const int MAX_N = 5 + 1;
int A[MAX_N], S[MAX_N], C[MAX_N];
int N, M;
void no() {
  cout << -1 << endl;
  exit(0);
}
void solve() {
  memset(A, -1, sizeof(A));
  for (int i = 0; i < (M); ++i) {
    int j = S[i] - 1;
    if (A[j] != -1 && A[j] != C[i]) no();
    A[j] = C[i];
  }
  if (A[0] == 0) {
    if (N == 1) {
      cout << 0 << endl;
      return;
    }
    no();
  }
  for (int i = 0; i < (N); ++i)
    if (A[i] == -1) A[i] = i > 0 ? 0 : 1;
  string res(N, '?');
  for (int i = 0; i < (N); ++i) res[i] = '0' + A[i];
  cout << res << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(12) << fixed;
  cin >> N >> M;
  for (int i = 0; i < (M); ++i) cin >> S[i] >> C[i];
  solve();
  return 0;
}
