#include <bits/stdc++.h>
using namespace std;
constexpr long long int MOD = 1000000007;
constexpr long double EPS = 1e-12;
long long int N, M, K, H, W, L, R;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  vector<int> v(N, -1);
  for (int i = 0; i < M; i++) {
    cin >> L >> R;
    L--;
    if (v[L] == -1) {
      v[L] = R;
    } else if (v[L] != R) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (N > 1 && v[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    if (v[i] == -1) {
      if (!i)
        cout << 1;
      else
        cout << 0;
    } else
      cout << v[i];
  }
  cout << endl;
  return 0;
}
