#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
void __p(long long x) { cout << x; }
void __p(int32_t x) { cout << x; }
void __p(float x) { cout << x; }
void __p(double x) { cout << x; }
void __p(long double x) { cout << x; }
void __p(char x) { cout << '\'' << x << '\''; }
void __p(const char *x) { cout << '\"' << x << '\"'; }
void __p(const string &x) { cout << '\"' << x << '\"'; }
void __p(bool x) { cout << (x ? "true" : "false"); }
void _p() { cout << "]\n"; }
template <typename T, typename V>
void __p(const pair<T, V> &x) {
  cout << '{';
  __p(x.first);
  cout << ',';
  __p(x.second);
  cout << '}';
}
template <typename T>
void __p(const T &x) {
  long long f = 0;
  cout << '{';
  for (auto &i : x) cout << (f++ ? "," : ""), __p(i);
  cout << "}";
}
template <typename T, typename... V>
void _p(T t, V... v) {
  __p(t);
  if (sizeof...(v)) cout << ", ";
  _p(v...);
}
long long po(long long x, long long p, long long m = inf) {
  long long ans = 1;
  x %= m;
  while (p > 0) {
    if (p & 1) ans = (ans * x) % m;
    p = p >> 1;
    x = (x * x) % m;
  }
  return ans;
}
long long inv(long long x, long long m = mod) { return po(x, m - 2, m) % m; }
const long long N = 1e6 + 6;
long long n, m, k, x, y, z, a, b, c, d, i, j, l, r, f;
void sol() {
  cin >> n >> m;
  vector<long long> v(n + 1, -1);
  while (m--) {
    cin >> x >> y;
    if (v[x] != -1 && v[x] != y) {
      cout << -1;
      return;
    }
    v[x] = y;
  }
  if (v[1] == 0 && n != 1) {
    cout << -1;
    return;
  }
  if (v[1] == -1) v[1] = 1;
  for (i = 1; i <= n; i++) cout << ((v[i] == -1) ? 0 : v[i]);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  sol();
  return 0;
}
