#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;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (m); i++) cin >> s[i] >> c[i];
  vector<int> a(n);
  for (int i = 0; i < (n); i++) a[i] = -1;
  for (int i = 0; i < (m); i++) {
    int j = s[i] - 1;
    int value = c[i];
    if (a[j] == -1) {
      a[j] = value;
    } else if (a[j] != value) {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (n >= 2 && a[0] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; i < (n); i++) {
    if (i == 0 && a[i] == -1)
      cout << 1;
    else if (a[i] == -1)
      cout << 0;
    else
      cout << a[i];
  }
  cout << endl;
  return 0;
}
