#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T>
void view(const std::vector<T> &v) {
  for (const auto &e : v) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv) {
  for (const auto &v : vv) {
    view(v);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, -1);
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (a[s] == -1 || a[s] == c) {
      a[s] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (a[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (a[0] == -1) {
    a[0] = 1;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == -1) {
      a[i] = 0;
    }
    ans += a[i] * pow(10, n - i - 1);
  }
  cout << ans << endl;
  return 0;
}
