#include <bits/stdc++.h>
using namespace std;
int mas[3] = {-1, -1, -1};
int main() {
  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b;
    cin >> a >> b;
    if (mas[a - 1] != -1 && mas[a - 1] != b) {
      cout << -1 << '\n';
      return 0;
    }
    mas[a - 1] = b;
  }
  string str;
  for (int i = 2; i >= 3 - n; i--) {
    if (mas[i] == -1) {
      if (i == 3 - n)
        str += "1";
      else
        str += "0";
    } else {
      str += to_string(mas[i]);
    }
  }
  reverse((str).begin(), (str).end());
  while (!str.empty() && str.front() == '0') str.erase(str.begin());
  if (str.empty())
    cout << -1 << '\n';
  else
    cout << str;
  return 0;
}
