#include <bits/stdc++.h>
using namespace std;
using Int = int64_t;
using Uint = uint64_t;
constexpr Uint mod = 1e9 + 7;
constexpr Int INF = INT_MAX;
template <typename T>
using Grid = vector<vector<T>>;
template <typename T, typename U>
using Umap = unordered_map<T, U>;
template <typename T>
using Uset = unordered_set<T>;
template <typename T>
using P = pair<T, T>;
void calc() {
  Int N, M;
  cin >> N >> M;
  vector<Int> s(M), c(M);
  for (Int(i) = 0; (i) < (M); ++(i)) cin >> s[i] >> c[i];
  vector<Int> ans(N, 10);
  for (Int(i) = 0; (i) < (M); ++(i)) {
    if (ans[s[i] - 1] != 10 && ans[s[i] - 1] != c[i]) {
      cout << -1;
      return;
    } else {
      ans[s[i] - 1] = c[i];
    }
  }
  if (ans[0] == 0) {
    cout << -1;
    return;
  }
  for (Int(i) = 0; (i) < (N); ++(i))
    if (ans[i] == 10) ans[i] = 0;
  for (Int(i) = 0; (i) < (N); ++(i)) cout << ans[i];
}
int main() {
  calc();
  return 0;
}
