#include <bits/stdc++.h>
using namespace std;
long long get(long long n) {
  long long ans = 0;
  while (n) ans++, n /= 10;
  return ans;
}
void solve() {
  long long i, j, n, m, x, y;
  cin >> n >> m;
  std::set<long long> v[n + 1];
  for (long long i = 0; i < m; i++) {
    cin >> x >> y;
    v[x].insert(y);
  }
  bool pos = 1;
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    if (v[i].size() > 1)
      pos = 0;
    else if (v[i].size() == 1) {
      if (n > 1 and i == 1 and *(v[i].begin()) == 0) pos = 0;
      ans = ans * 10 + *(v[i].begin());
    } else {
      if (i > 1)
        ans = ans * 10;
      else if (n > 1)
        ans = ans * 10 + 1;
    }
  }
  if (ans == 0 and n == 1)
    pos = 1;
  else if (get(ans) != n)
    pos = 0;
  cout << (pos ? ans : -1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
}
