#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  pair<int, int> p[M];
  map<int, int> mp;
  bool exist = true;
  for (int i = 0; i < M; ++i) {
    cin >> s[i] >> c[i];
    p[i] = make_pair(s[i], c[i]);
  }
  string S[N], T;
  for (int i = 0; i < N; ++i) {
    S[i] = '0';
  }
  S[0] = '1';
  sort(p, p + M);
  exist = true;
  for (int i = 0; i < M; ++i) {
    S[p[i].first - 1] = toString(p[i].second);
  }
  for (int i = 0; i < M; ++i) {
    if (S[p[i].first - 1] != toString(p[i].second)) {
      exist = false;
    }
  }
  for (int i = 0; i < N; ++i) {
    T += S[i];
  }
  long long res = 0;
  res = toInt(T);
  string R = toString(res);
  int line = R.length();
  if (line != N) {
    exist = false;
  }
  if (exist) {
    cout << R;
  } else {
    cout << -1;
  }
}
