#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int main(int argc, char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
  int n, m;
  cin >> n >> m;
  map<int, int> sc;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (sc.find(s) != sc.end() && sc.at(s) != c) {
      cout << -1 << endl;
      return 0;
    } else {
      sc.insert(make_pair(s, c));
    }
  }
  string ans(n, '0');
  auto it = sc.begin();
  for (int i = 1; i <= n; i++) {
    if (it == sc.end()) break;
    if (it->first != i) {
      if (i == 1) ans[i - 1] = '1';
      continue;
    } else {
      if (i == 1 && it->second == 0) {
        if (n == 1)
          ans[i - 1] = '0';
        else {
          cout << -1 << endl;
          return 0;
        }
      } else {
        ans[i - 1] = it->second + '0';
      }
    }
    it++;
  }
  cout << ans << endl;
  return 0;
}
