#include <bits/stdc++.h>
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace {
struct INIT {
  INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} INIT;
}  // namespace
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (int)(m); ++i) cin >> s[i] >> c[i];
  vector<int> v(n);
  for (int i = 0; i < (int)(m); ++i) {
    v[s[i] - 1] = c[i];
  }
  if (v[0] == 0) v[0] = 1;
  bool ok = true;
  for (int i = 0; i < (int)(m); ++i) {
    if (v[s[i] - 1] != c[i]) ok = false;
  }
  string ans;
  for (int i = 0; i < (int)(n); ++i) ans += to_string(v[i]);
  cout << (ok ? ans : "-1") << endl;
  return 0;
}
