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