#include <bits/stdc++.h>
using namespace std;
const long INF = 1e9;
const long MOD = 1e9 + 7;
int power(int n, int t) {
  int s = 1;
  for (int i = 0; i < int(t); i++) {
    s *= n;
  }
  return s;
}
int main() {
  int n, m, ans = 0;
  vector<bool> rank(3, false);
  cin >> n >> m;
  for (int i = 0; i < int(m); i++) {
    int s, c;
    cin >> s >> c;
    if (rank.at(n - s)) {
      cout << -1 << endl;
      return 0;
    }
    if (n > 1 && s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (c != 0) {
      if (ans / power(10, n - s) == c) {
        continue;
      }
      ans += c * power(10, n - s);
    } else {
      ans = max(ans, power(10, 4 - s));
    }
    rank.at(n - s) = true;
  }
  cout << ans << endl;
  return 0;
}
