#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
int main() {
  int N;
  cin >> N;
  vector<int> a(N, -1);
  int m;
  cin >> m;
  for (int mi = 0; mi < (int)(m); ++mi) {
    int s, c;
    cin >> s >> c;
    s--;
    if (a[s] == -1) {
      a[s] = c;
    } else {
      if (a[s] != c) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (a[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    if (a[i] == -1) {
      if (i == 0)
        cout << 1;
      else
        cout << 0;
    } else {
      cout << a[i];
    }
  }
  cout << endl;
}
