#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);
  }
}
template <typename T>
void view(T e) {
  std::cout << e << std::endl;
}
template <typename T>
void viewarr(T arr[], int n) {
  for (int i = 0; i < n; ++i) std::cout << arr[i] << " ";
  std::cout << std::endl;
}
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;
}
ll qp(ll a, ll b) {
  ll ans = 1;
  do {
    if (b & 1) ans = 1ll * ans * a;
    a = 1ll * a * a;
  } while (b >>= 1);
  return ans;
}
ll qp(ll a, ll b, ll mo) {
  ll ans = 1;
  do {
    if (b & 1) ans = 1ll * ans * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return ans;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = (int)(0); i < (int)(M); ++i) cin >> s[i] >> c[i];
  for (int i = (int)(0); i < (int)(M); ++i) --s[i];
  vector<int> num(N, -1);
  bool ok = true;
  for (int i = (int)(0); i < (int)(M); ++i) {
    if (num[s[i]] != -1 && num[s[i]] != c[i]) {
      ok = false;
      continue;
    }
    num[s[i]] = c[i];
  }
  if (N != 1 && num[0] == 0) ok = false;
  if (!ok)
    cout << -1 << endl;
  else {
    if (num[0] == -1) num[0] = 1;
    for (int i = (int)(1); i < (int)(N); ++i)
      if (num[i] == -1) num[i] = 0;
    int ans = 0;
    int p = 1;
    for (int i = ((int)(N)-1); i >= (0); --i) {
      ans += num[i] * p;
      p *= 10;
    }
    cout << ans << endl;
  }
  return 0;
}
