#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> num(n, -1);
  int s, c;
  for (int i = 0; i < (m); ++i) {
    cin >> s >> c;
    if (s > n) {
      cout << -1 << endl;
      return 0;
    }
    if (num[s - 1] == -1) {
      num[s - 1] = c;
    } else if (num[s - 1] == c) {
      continue;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (num[0] == 0) {
    cout << -1 << endl;
    return 0;
  } else if (num[0] == -1) {
    num[0] = 1;
  }
  for (auto& v : num) {
    if (v == -1) {
      cout << 0;
    } else {
      cout << v;
    }
  }
  cout << endl;
  return 0;
}
