#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> m;
  for (int i = 0; i < (M); ++i) {
    int s, c;
    cin >> s >> c;
    if ((m.count(s) && m[s] != c) || (s == 1 && c == 0)) {
      cout << -1 << endl;
      return (0);
    } else if (N == 1 && (s == 2 && c == 0)) {
      cout << -1 << endl;
      return (0);
    } else
      m[s] = c;
  }
  if (!m.count(3)) m[3] = 0;
  if (N == 3 && !m.count(2)) m[2] = 0;
  for (int i = 0; i < (N); ++i) cout << m.at(i + 1);
  cout << endl;
}
