#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate {
  ios_accelerate() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} CALL;
using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = vector<vector<T>>;
template <typename T>
using P = pair<T, T>;
const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;
template <typename T>
inline void upsort(vector<T>& x) {
  sort(x.begin(), x.end());
}
template <typename T>
inline void downsort(vector<T>& x) {
  sort(x.begin(), x.end(), greater<T>());
}
template <typename T>
inline void col(T x) {
  cout << x << '\n';
}
template <>
inline void col(double x) {
  cout << fixed << setprecision(12) << x << '\n';
}
signed main() {
  int n, m;
  cin >> n >> m;
  V<int> s(m), c(m);
  for (auto(i) = (m)*0; (i) < (m); (i)++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  V<int> num(n, -1);
  for (auto(i) = (m)*0; (i) < (m); (i)++) {
    if (num[s[i]] > 0 && num[s[i]] != c[i]) {
      col("-1");
      return 0;
    }
    num[s[i]] = c[i];
  }
  if (num[0] == 0) {
    col("-1");
    return 0;
  }
  if (num[0] == -1) {
    num[0] = 1;
  }
  for (auto(i) = (1); (i) < (n); (i)++) {
    if (num[i] == -1) {
      num[i] = 0;
    }
  }
  int ans = 0, x = 1;
  for (int i = n - 1; i >= 0; i--) {
    ans += num[i] * x;
    x *= 10;
  }
  col(ans);
  return 0;
}
