#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long N = 200 * 1000 + 9;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
long long i, j, k;
void solve() {
  long long n, m;
  cin >> n >> m;
  map<long long, long long> mpp;
  for (i = 0; i < m; i++) {
    long long x;
    cin >> x;
    long long y;
    cin >> y;
    y = y + 1;
    if (x == 1 and y == 0 and n > 1) {
      cout << -1 << '\n';
      return;
    }
    if (mpp[x] and mpp[x] != y) {
      cout << -1 << '\n';
      return;
    }
    mpp[x] = y;
  }
  for (i = 0; i < n; i++) {
    if (mpp[i + 1])
      cout << mpp[i + 1] - 1;
    else
      cout << 0;
  }
  return;
}
signed main() {
  solve();
  return 0;
}
