#include <bits/stdc++.h>
using namespace std;
template <class T>
using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;
template <class T>
pair<T, size_t> max(vector<T> &x) {
  auto it = max_element((x).begin(), (x).end());
  return make_pair(*it, it - x.begin());
}
template <class T>
pair<T, size_t> min(vector<T> &x) {
  auto it = min_element((x).begin(), (x).end());
  return make_pair(*it, it - x.begin());
}
template <class T>
inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
void solve(long long N, long long M, std::vector<long long> s,
           std::vector<long long> c) {
  vi digits(N, 0);
  vi fixed(N, -1);
  if (N > 1) {
    digits[0] = 1;
  }
  for (int i = int(0); i < int(M); ++i) {
    if (fixed[s[i] - 1] < 0) {
      digits[s[i] - 1] = c[i];
      fixed[s[i] - 1] = c[i];
    } else {
      if (fixed[s[i] - 1] != c[i]) {
        cout << -1 << endl;
        return;
      }
    };
  }
  if (digits[0] == 0) {
    cout << -1 << endl;
    return;
  }
  ll ret = 0;
  for (int i = int(0); i < int(N); ++i) {
    ret *= 10;
    ret += digits[i];
  }
  cout << ret << endl;
  return;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  long long N;
  std::cin >> N;
  long long M;
  std::cin >> M;
  std::vector<long long> s(M);
  std::vector<long long> c(M);
  for (int i = 0; i < M; i++) {
    std::cin >> s[i];
    std::cin >> c[i];
  }
  solve(N, M, std::move(s), std::move(c));
  return 0;
}
