#include <bits/stdc++.h>
using namespace std;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  long long ans[n];
  for (long long i = 0; i < n; i++) ans[i] = -1;
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    if (ans[a] == -1) {
      ans[a] = b;
    } else if (ans[a] != b) {
      cout << "-1"
           << "\n";
      return 0;
    }
  }
  for (long long i = 0; i < n; i++) {
    if (ans[i] == -1) {
      if (i == 0)
        cout << 1;
      else
        cout << 0;
    } else {
      if (i == 0 && ans[i] == 0) {
        cout << -1 << "\n";
        return 0;
      }
      cout << ans[i];
    }
  }
  cout << "\n";
  return 0;
}
