#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  for (int i = 0; i < ((int)v.size()); ++i) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}
template <typename T, size_t S>
void printArray(const T (&array)[S]) {
  for (auto val : array) std::cout << val << ", ";
  std::cout << "\n";
}
const int mod = 1e9 + 7;
const int inf = 1e9 + 5;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);
  int n, m;
  std::cin >> n >> m;
  map<int, int> conv;
  bool ok = true;
  for (int i = 0; i < (m); ++i) {
    int s, c;
    std::cin >> s >> c;
    s--;
    if (conv.count(s) && conv[s] != c) ok = false;
    conv[s] = c;
  }
  int ans = 0;
  for (int i = 0; i < (n); ++i) {
    if (conv.count(i))
      ans = ans * 10 + conv[i];
    else if (i == 0)
      ans = 1;
    else
      ans = ans * 10 + 0;
  }
  if (conv.count(0) && conv[0] == 0) ok = false;
  if (!ok) ans = -1;
  std::cout << ans << "\n";
}
