#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e09 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> data;
  int answer = 0;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if ((data.count(s) and data.at(s) != c) or (s == 1 and n >= 2 and c == 0)) {
      answer = -1;
    } else if (!data.count(s)) {
      data[s] = c;
    }
  }
  for (int i = 2; i <= n; i++) {
    if (data.count(i) and answer != -1) {
      answer += pow(10, n - i) * data.at(i);
    }
  }
  if (data.count(1) and answer != -1) {
    answer += pow(10, n - 1) * data.at(1);
  } else if (answer != -1) {
    answer += pow(10, n - 1);
  }
  cout << answer << endl;
}
