#include <bits/stdc++.h>
using namespace std;
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;
}
template <typename T>
std::string printVector(const std::vector<T> &data) {
  std::stringstream ss;
  std::ostream_iterator<T> out_it(ss, ", ");
  ss << "[";
  std::copy(data.begin(), data.end() - 1, out_it);
  ss << data.back() << "]";
  return ss.str();
}
template <typename T>
void print_array(const T &ary, int size) {
  for (int i = (0); i < (size); ++i) {
    cout << ary[i] << " ";
  }
  cout << endl;
}
const int MOD = 1e9 + 7;
const long long LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
signed main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(12);
  int N, M;
  cin >> N >> M;
  vector<int> dig(N, -1);
  for (int i = (0); i < (M); ++i) {
    int s, c;
    cin >> s >> c;
    if (s > N) {
      cout << -1 << endl;
      return 0;
    }
    if (dig[s - 1] == -1) {
      dig[s - 1] = c;
    } else {
      if (dig[s - 1] != c) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (dig[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (dig[0] == -1) {
    dig[0] = 1;
  }
  for (int i = (0); i < (N); ++i) {
    if (dig[i] == -1) {
      cout << 0;
    } else {
      cout << dig[i];
    }
  }
  cout << endl;
}
