#include <bits/stdc++.h>
using namespace std;
template <typename First>
void debug_print_in(First first) {
  cerr << first << endl;
  return;
}
template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest) {
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}
void IN(void) { return; }
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest) {
  cin >> first;
  IN(rest...);
  return;
}
template <typename First>
void OUT(First first) {
  cout << first << endl;
  return;
}
template <typename First, typename... Rest>
void OUT(First first, Rest... rest) {
  cout << first << " ";
  OUT(rest...);
  return;
}
template <class t, class u>
void chmax(t& a, u b) {
  if (a < b) a = b;
};
template <class t, class u>
void chmin(t& a, u b) {
  if (a > b) a = b;
};
int popcount(int t) { return __builtin_popcount(t); }
int popcount(long long t) { return __builtin_popcountll(t); }
template <typename T>
void vec_print(vector<T> VEC) {
  for (long long i = (long long)0; i < (long long)VEC.size(); ++i) {
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};
template <typename T>
void mat_print(vector<vector<T>> MAT) {
  for (long long i = (long long)0; i < (long long)MAT.size(); ++i) {
    for (long long j = (long long)0; j < (long long)MAT[i].size(); ++j) {
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};
constexpr int INF = (1 << 30);
constexpr long long INFLL = 1LL << 62;
constexpr long double EPS = 1e-12;
constexpr long long MOD = (long long)((1E+9) + 7);
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, M;
  IN(N, M);
  map<long long, long long> mp;
  vector<long long> s(M), c(M);
  for (long long i = (long long)0; i < (long long)M; ++i) {
    IN(s[i], c[i]);
    s[i]--;
    if (mp.find(s[i]) != mp.end()) {
      if (mp[s[i]] != c[i]) {
        printf("-1\n");
        return 0;
      }
    }
    mp[s[i]] = c[i];
  }
  bool flag = false;
  for (long long i = (long long)0; i < (long long)N; ++i) {
    if (mp.find(i) == mp.end()) {
      if (flag) {
        mp[i] = 0;
      } else {
        mp[i] = 1;
        flag = true;
      }
    } else {
      if (mp[i] > 0) flag = true;
    }
  }
  if (mp[0] == 0) {
    if (N == 1) {
      OUT(0);
    } else {
      OUT(-1);
    }
    return 0;
  }
  long long ans = 0;
  for (long long i = (long long)0; i < (long long)N; ++i) {
    ans *= 10;
    ans += mp[i];
  }
  OUT(ans);
  return 0;
}
