#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const double PI = 3.141592653589793238463;
const long long N = 2e5 + 9;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int x, m;
  cin >> x >> m;
  map<int, int> mp;
  int l, r;
  vector<int> ans(x, 0);
  bool b = true;
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    l--;
    if (mp.find(l) != mp.end()) {
      if (mp[l] != r) {
        b = false;
        cout << -1 << '\n';
        return 0;
      }
    } else {
      if (l == 0 && r == 0) {
        cout << -1 << '\n';
        return 0;
      }
      mp[l] = r;
      ans[l] = r;
    }
  }
  if (ans[0] == 0) ans[0] = 1;
  for (int i = 0; i < x; i++) cout << ans[i];
  return 0;
}
