#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}";
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
    os << *itr;
    itr++;
    if (itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
    os << *itr;
    itr++;
    if (itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
void dump_func() { cout << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
  cout << head;
  if (sizeof...(Tail) > 0) {
    cout << ", ";
  }
  dump_func(std::move(tail)...);
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct aaa {
  aaa() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} aaaaaaa;
signed main() {
  int N, M;
  cin >> N >> M;
  int hoge[5];
  for (int i = 0, i_len = (5); i < i_len; ++i) {
    hoge[i] = -1;
  }
  bool inv = false;
  for (int i = 0, i_len = (M); i < i_len; ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (s > N && c != 0) {
      inv = true;
    }
    if (hoge[s] != -1 && hoge[s] != c) {
      inv = true;
      ;
    }
    hoge[s] = c;
  }
  if (inv) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  int digi = 1;
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    int kk = 0;
    if (hoge[N - 1 - i] != -1) {
      kk = hoge[N - 1 - i];
    }
    ans += kk * digi;
    digi *= 10;
  };
  if (N != to_string(ans).size()) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
