#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  if (fopen("inp.txt", "r"))
    freopen("inp.txt", "r", stdin), freopen("out.txt", "w", stdout);
  ;
  long long n, m;
  cin >> n >> m;
  long long a[n];
  for (long long i = 0; i < n; ++i) a[i] = -1;
  bool ok = 1;
  for (long long i = 0; i < m; ++i) {
    long long s, c;
    cin >> s >> c;
    s--;
    if (a[s] == -1)
      a[s] = c;
    else {
      if (a[s] != c) ok = 0;
    }
  }
  if (n == 1) {
    if (ok) {
      if (a[0] != -1)
        cout << a[0];
      else
        cout << 0;
    } else
      cout << -1;
  }
  if (n > 1) {
    if (a[0] == 0) ok = 0;
    if (a[0] == -1) a[0] = 1;
    for (long long i = 0; i < 3; ++i)
      if (a[i] == -1) a[i] = 0;
    if (ok)
      cout << a[0] << a[1] << a[2];
    else
      cout << -1;
  }
  return 0;
}
