#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;
using mat2d_t = std::vector<std::vector<int64_t>>;
int main(int argc, char **argv) {
  int n, m;
  cin >> n >> m;
  std::vector<int> v(n, -1);
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    if (v[s - 1] != -1 && v[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
    v[s - 1] = c;
  }
  if (v[0] == -1 || v[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  int ans{0};
  for (int i = 0; i < v.size(); ++i) {
    int num;
    if (v[i] == -1) {
      num = 0;
    } else {
      num = v[i];
    }
    ans = ans * 10 + num;
  }
  cout << ans << endl;
  return 0;
}
