#include <bits/stdc++.h>
using namespace std;
long long mod;
long long nc2(long long n) {
  if (n < 2) return 0;
  long long pp = n - 1;
  if (pp % 2 == 0)
    pp /= 2;
  else
    n /= 2;
  n *= pp;
  return n;
}
long long ans, cp;
vector<long long> v1, v2;
long long bs(long long look) {
  long long l = 0, hi = v2.size() - 1, poss = -1;
  if (look < v2[0]) return hi + 1;
  if (look > v2[hi]) return 0;
  while (l <= hi) {
    long long mid = l + (hi - l) / 2;
    if (v2[mid] > look) {
      poss = mid;
      hi = mid - 1;
    } else
      l = mid + 1;
  }
  return v2.size() - poss;
}
bool cpp(long long a[], long long n) {
  long long mn = a[0];
  for (long long i = 1; i < n; ++i) {
    if (a[i] < mn) return false;
    mn = a[i];
  }
  return true;
}
void solve() {
  long long n, m;
  cin >> n >> m;
  long long st[n];
  for (long long i = 0; i < n; ++i) st[i] = -1;
  while (m--) {
    long long x, y;
    cin >> x >> y;
    --x;
    if (x >= m) {
      cout << -1;
      return;
    }
    if (st[x] == -1)
      st[x] = y;
    else {
      if (st[x] != y) {
        cout << -1;
        return;
      }
    }
  }
  if (st[n - 1] == -1)
    cout << -1;
  else {
    for (long long i = 0; i < n; ++i) {
      if (st[i] == -1)
        cout << 0;
      else
        cout << st[i];
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  mod = 1e9 + 7;
  long long t;
  t = 1;
  while (t--) solve();
  return 0;
}
