#include <bits/stdc++.h>
using namespace std;
long long N, M;
long long s[5], c[5];
long long d[3];
void _main() {
  cin >> N >> M;
  if (N == 1 && M == 0) {
    cout << 0 << '\n';
    return;
  }
  for (long long i = (0); i < (N); ++i) d[i] = -1;
  bool ng = false;
  for (long long i = (0); i < (M); ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
    if (d[s[i]] < 0)
      d[s[i]] = c[i];
    else if (d[s[i]] != c[i])
      ng = true;
  }
  if (d[0] == 0) ng = true;
  if (ng) {
    cout << -1 << '\n';
    return;
  }
  for (long long i = (0); i < (N); ++i) cout << (d[i] < 0 ? (i == 0) : d[i]);
  cout << '\n';
}
signed main(signed argc, char **argv) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
  _main();
  return 0;
}
