#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class t, class u>
bool chmax(t &a, u b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class t, class u>
bool chmin(t &a, u b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  int c[3] = {-1, -1, -1};
  for (int i = int(0); i < int(m); i++) {
    int a, b;
    cin >> a >> b;
    if (c[a - 1] != -1 && c[a - 1] != b) {
      cout << -1 << endl;
      return 0;
    }
    c[a - 1] = b;
  }
  if (c[0] == 0) {
    if (n == 1) {
      cout << 0 << endl;
    } else {
      cout << -1 << endl;
    }
  } else {
    string s = "";
    for (int i = int(0); i < int(n); i++) {
      if (c[i] == -1) {
        s.push_back('0');
      } else {
        s.push_back('0' + c[i]);
      }
    }
    if (s[0] == '0') {
      s[0] = '1';
    }
    cout << s << endl;
  }
  return 0;
}
