#include <bits/stdc++.h>
const long long LLINF = 1LL << 60;
const int INF = 1e9;
const long long MOD = 1000000007;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<int> v(n, INF);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (v[s] != INF && v[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    v[s] = c;
  }
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      if (v[i] == 0) {
        cout << -1 << endl;
        return 0;
      } else if (v[i] == INF)
        cout << 1;
      else
        cout << v[i];
    } else {
      if (v[i] == INF)
        cout << 0;
      else
        cout << v[i];
    }
  }
  cout << endl;
  return 0;
}
