#include <bits/stdc++.h>
using namespace std;
long long p = 1000000007;
vector<long long> kai;
vector<long long> inv_kai;
long long rui(long long a, long long n, long long mod) {
  if (n == 0) {
    return 1 % mod;
  }
  long long x = rui(a, n / 2, mod);
  x *= x;
  x %= mod;
  if (n % 2 == 1) {
    x *= a;
    x %= mod;
  }
  return x;
}
long long root(long long x, vector<long long>& pa) {
  if (pa[x] == -1) {
    return x;
  }
  long long ans = root(pa[x], pa);
  pa[x] = ans;
  return ans;
}
bool mar(long long x, long long y, vector<long long>& pa) {
  x = root(x, pa);
  y = root(y, pa);
  if (x != y) {
    pa[x] = y;
  }
  return (x != y);
}
long long gcd(long long x, long long y) {
  if (x < y) {
    return gcd(y, x);
  }
  if (y == 0) {
    return x;
  }
  return gcd(y, x % y);
}
long long lcm(long long x, long long y) {
  x = abs(x);
  y = abs(y);
  return x * y / gcd(x, y);
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
void make_kai(long long max_kai) {
  kai = vector<long long>(max_kai, 1);
  inv_kai = kai;
  for (long long i = 0; i < max_kai - 1; i++) {
    kai[i + 1] = kai[i] * (i + 1);
    kai[i + 1] %= p;
    inv_kai[i + 1] = modinv(kai[i + 1], p);
  }
}
long long com(long long n, long long r) {
  if ((n < 0) || (r < 0) || (r > n)) {
    return 0;
  }
  long long ans = (kai[n] * inv_kai[r]) % p;
  return (ans * inv_kai[n - r]) % p;
}
vector<long long> uni(vector<long long> x) {
  if (x.size() == 0) {
    return x;
  }
  sort(x.begin(), x.end());
  long long n = x.size();
  vector<long long> ans(1, x[0]);
  for (long long j = 1; j < n; j++) {
    if (x[j - 1] != x[j]) {
      ans.push_back(x[j]);
    }
  }
  x = ans;
  return x;
}
void pr(vector<long long>& v) {
  long long n = v.size();
  if (n != 0) {
    cout << v[0];
    for (long long i = 0; i < n - 1; i++) {
      cout << " " << v[i + 1];
    }
    cout << endl;
  }
}
vector<long long> dijk(vector<vector<pair<long long, long long>>>& way,
                       long long st, long long inf) {
  long long n = way.size();
  vector<long long> dist(n, inf);
  dist[st] = 0;
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      pq;
  pq.push(make_pair(0, st));
  vector<bool> is_checked(n, false);
  while (!pq.empty()) {
    pair<long long, long long> x = pq.top();
    pq.pop();
    long long pot = x.second;
    if (!is_checked[pot]) {
      is_checked[pot] = true;
      for (auto y : way[pot]) {
        long long nex_dist = x.first + y.second;
        long long nex_pot = y.first;
        if (dist[nex_pot] > nex_dist) {
          dist[nex_pot] = nex_dist;
          pq.push(make_pair(nex_dist, y.first));
        }
      }
    }
  }
  return dist;
}
vector<long long> mul(vector<long long>& a, vector<long long>& b) {
  long long n = a.size();
  long long m = b.size();
  vector<long long> ans(n + m - 1, 0);
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      ans[i + j] += a[i] * b[j];
      ans[i + j] %= p;
    }
  }
  return ans;
}
vector<long long> rui_p(vector<long long>& a, long long n) {
  if (n == 0) {
    return {1};
  }
  vector<long long> qans = rui_p(a, n / 2);
  qans = mul(qans, qans);
  if (n % 2 == 1) {
    qans = mul(qans, a);
  }
  return qans;
}
bool is_prime(long long n) {
  if (n == 0 || n == 1) {
    return false;
  }
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
void per(long long& ans) {
  ans %= p;
  if (ans < 0) {
    ans += p;
  }
}
vector<vector<long long>> disj_min(vector<long long>& v) {
  long long n = v.size();
  vector<vector<long long>> ret(22, vector<long long>(n));
  ret[0] = v;
  for (long long i = 0; i < 21; i++) {
    for (long long j = 0; j < n; j++) {
      long long nex = j + (1 << i);
      if (nex < n) {
        ret[i + 1][j] = min(ret[i][j], ret[i][nex]);
      } else {
        ret[i + 1][j] = ret[i][j];
      }
    }
  }
  return ret;
}
vector<vector<long long>> disj_max(vector<long long>& v) {
  long long n = v.size();
  vector<vector<long long>> ret(22, vector<long long>(n));
  ret[0] = v;
  for (long long i = 0; i < 21; i++) {
    for (long long j = 0; j < n; j++) {
      long long nex = j + (1 << i);
      if (nex < n) {
        ret[i + 1][j] = max(ret[i][j], ret[i][nex]);
      } else {
        ret[i + 1][j] = ret[i][j];
      }
    }
  }
  return ret;
}
long long find_min(vector<vector<long long>>& dv, long long l, long long r) {
  long long i = 21;
  while (l + (1 << i) > r) {
    i--;
  }
  return min(dv[i][l], dv[i][r - (1 << i)]);
}
long long find_max(vector<vector<long long>>& dv, long long l, long long r) {
  long long i = 21;
  while (l + (1 << i) > r) {
    i--;
  }
  return max(dv[i][l], dv[i][r - (1 << i)]);
}
void pri(vector<long long>& v) {
  if (v.size() == 0) {
    return;
  }
  cout << v[0];
  for (long long i = 0; i < v.size() - 1; i++) {
    cout << " " << v[i + 1];
  }
  cout << endl;
  return;
}
long long solve(long long st, vector<pair<long long, long long>>& par,
                vector<long long>& dp) {
  if (dp[st] == -1) {
    dp[st] = solve(par[st].first, par, dp) * par[st].second;
    dp[st] %= p;
  }
  return dp[st];
}
vector<vector<long long>> dbl(vector<long long>& v) {
  vector<vector<long long>> ans(20, vector<long long>(v));
  long long n = v.size();
  for (long long i = 0; i < 19; i++) {
    for (long long j = 0; j < n; j++) {
      ans[i + 1][j] = ans[i][ans[i][j]];
    }
  }
  return ans;
}
long long lca(long long s, long long t, long long diff,
              vector<vector<long long>>& pa) {
  if (diff < 0) {
    return lca(t, s, -diff, pa);
  }
  for (long long i = 0; i < 19; i++) {
    if ((diff & (1 << i)) != 0) {
      s = pa[i][s];
    }
  }
  for (long long i = 19; i >= 0; i--) {
    if (pa[i][s] != pa[i][t]) {
      s = pa[i][s];
      t = pa[i][t];
    }
  }
  if (s != t) {
    s = pa[0][s];
  }
  return s;
}
signed main() {
  long long n;
  cin >> n;
  vector<long long> ans(n, -1);
  long long m;
  cin >> m;
  for (long long i = 0; i < m; i++) {
    long long s, c;
    cin >> s >> c;
    s--;
    if (ans[s] != -1 && ans[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    ans[s] = c;
  }
  for (long long i = 0; i < n; i++) {
    if (ans[i] == -1) {
      ans[i]++;
      if (i == 0) {
        ans[i]++;
      }
    } else if (ans[i] == 0 && i == 0) {
      cout << -1 << endl;
      return 0;
    }
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
