#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, f = 0, ans = 0;
  cin >> n >> m;
  if (n == 1 && m == 0) {
    cout << 0;
    return 0;
  } else if (n == 2 && m == 0) {
    cout << 10;
    return 0;
  } else if (n == 3 && m == 0) {
    cout << 100;
    return 0;
  }
  vector<int> a(m);
  vector<int> b(m);
  vector<int> c(44);
  for (int i = 0; i < m; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  for (int i = 0; i < m; i++) {
    if (a.at(i) == 1 && b.at(i) == 0) {
      if (n == 1) {
        cout << 0;
        return 0;
      }
      cout << -1;
      return 0;
    }
    for (int j = 0; j < m; j++) {
      if (a.at(i) == a.at(j) && b.at(i) != b.at(j)) {
        cout << -1;
        return 0;
      };
    }
    if (c.at(a.at(i)) == 0) {
      ans = ans + b.at(i) * pow(10, n - a.at(i));
    }
    c.at(a.at(i))++;
  }
  if (n == 2 && c.at(2) == 0) ans + 10;
  if (n == 3 && c.at(1) == 0) ans + 100;
  cout << ans;
}
