#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
const int mod = 1e9 + 7;
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;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (n); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  vector<int> ans(n, -1);
  for (int i = 0; i < (m); i++) {
    int S = s[i];
    int C = c[i];
    if (ans[S] == -1) {
      ans[S] = C;
    } else {
      if (ans[S] != C) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  for (int i = (1); i < (n); i++) {
    if (ans[i] == -1) {
      ans[i] = 0;
    }
  }
  if (ans[0] == -1) ans[0] = 1;
  if (ans[0] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; i < (n); i++) cout << ans[i];
  cout << endl;
}
