#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n, -1);
  long long x, y;
  for (long long i = 0; i < m; i++) {
    cin >> x >> y;
    if (x > n) {
      cout << "-1";
      return;
    }
    x--;
    if ((a[x] != -1) && (a[x] != y)) {
      cout << "-1";
      return;
    } else if (n != 1 && x == 0 && y == 0) {
      cout << "-1";
      return;
    } else {
      a[x] = y;
    }
  }
  if (a[0] == -1) {
    a[0] = 1;
  }
  for (long long i = 0; i < n; i++) {
    if (a[i] == -1)
      cout << "0";
    else
      cout << a[i];
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) solve();
  return 0;
}
