#include <bits/stdc++.h>
const double INF = 1e+09;
const int MOD = 1e9 + 7;
using namespace std;
template <typename _Ty>
ostream& operator<<(ostream& ostr, const vector<_Ty>& v) {
  if (v.empty()) {
    ostr << "{ }";
    return ostr;
  }
  ostr << "{" << v.front();
  for (auto itr = ++v.begin(); itr != v.end(); itr++) {
    ostr << ", " << *itr;
  }
  ostr << "}";
  return ostr;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main(void) {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = (0); i < (M); ++i) {
    cin >> s[i] >> c[i];
  }
  vector<int> flag(M);
  for (int i = (0); i < (M); ++i) {
    flag[i] = 10;
  }
  bool res = true;
  for (int i = (0); i < (M); ++i) {
    int tmp = s[i] - 1;
    int conf = flag[tmp];
    if (conf == 10) {
      flag[tmp] = c[i];
    } else {
      if (conf != c[i] and s[i] != 1 and c[i] != 0) {
        res = false;
      }
    }
  }
  for (int i = (0); i < (M); ++i) {
    if (s[i] == 1 and c[i] == 0) {
      res = false;
    }
  }
  int ans = 0;
  if (!res)
    ans = -1;
  else {
    for (int i = (0); i < (M); ++i) {
      int val = pow(10, N - i - 1);
      int tmp = flag[i];
      if (tmp == 10) {
        tmp = 0;
      }
      ans += tmp * val;
    }
  }
  cout << ans << endl;
  return 0;
}
