#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector<vector<long long>>;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(m);
  vector<long long> c(m);
  for (long long i = 0; i < (m); i++) {
    cin >> s.at(i) >> c.at(i);
  }
  vector<long long> vec(3);
  for (long long i = 0; i < (3); i++) {
    vec.at(i) = -1;
  }
  long long ans = -1;
  for (long long i = 0; i < (m); i++) {
    if (vec.at(s.at(i) - 1) == -1) {
      vec.at(s.at(i) - 1) = c.at(i);
    } else {
      if (c.at(i) == vec.at(s.at(i) - 1)) {
        continue;
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (vec.at(0) == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (long long i = 0; i < (n); i++) {
    if (vec.at(i) == -1) {
      vec.at(i) = 0;
    }
    cout << vec.at(i);
  }
  cout << endl;
}
