#include <bits/stdc++.h>
using namespace std;
using pii = pair<int64_t, int64_t>;
constexpr int64_t INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;
signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int64_t n, m, cnt = 0;
  int64_t a, b;
  cin >> n >> m;
  vector<int64_t> x;
  x.resize(n, -1);
  for (int64_t i = (0); i < (m); ++i) {
    cin >> a >> b;
    if (x[a - 1] == -1 || x[a - 1] == b) {
      x[a - 1] = b;
    } else {
      cout << -1 << '\n';
      return 0;
    }
  }
  for (int64_t i = (0); i < (n); ++i) {
    if (i != 0) {
      cnt *= 10;
    }
    if (x[0] == -1) {
      x[0] = 1;
    } else if (x[i] == -1) {
      x[i] = 0;
    }
    cnt += x[i];
  }
  cout << cnt << '\n';
}
