#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  map<int, int> num;
  for (int i = 0; i < (n); i++) num.insert(make_pair(i + 1, -1));
  bool ans = true;
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    if (num[s] != -1 && num[s] != c)
      ans = false;
    else
      num[s] = c;
    if (n == 3 && s == 1 && c == 0) ans = false;
    if (n == 2 && s == 1 && c == 0) ans = false;
  }
  if (ans) {
    string s;
    for (auto [k, v] : num) {
      if (v == -1)
        s += '0';
      else
        s += v + '0';
    }
    cout << stoi(s) << '\n';
  } else
    cout << -1 << '\n';
  return 0;
}
