#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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;
}
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n, -1);
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    if (s > n) {
      cout << -1 << endl;
      return 0;
    }
    if (v[s - 1] != -1 && v[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
    v[s - 1] = c;
  }
  if (v[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (v[0] == -1)
    cout << 1;
  else
    cout << v[0];
  for (int i = 1; i < n; i++) {
    if (v[i] != -1)
      cout << v[i];
    else
      cout << 0;
  }
  cout << endl;
}
