#include <bits/stdc++.h>
using namespace std;
const int tINF = (int)INT_MAX;
const long long lINF = (long long)LLONG_MAX;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> ar(n + 1, 0);
  bool f = 0;
  bool ans = 0;
  map<int, int> mp;
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    if (s == 1) f = 1;
    ar[s] = c;
    if (mp.find(s) == mp.end()) {
      mp[s] = c;
    } else if (mp[s] != c)
      ans = 1;
  }
  if (ans) {
    cout << -1 << '\n';
    return 0;
  }
  if (n == 1) {
    cout << ar[1] << '\n';
  } else {
    if (ar[1] == 0 && ar[2] == 0) {
      if (f) {
        cout << -1 << '\n';
        return 0;
      } else
        ar[1] = 1;
    }
  }
  for (int i = 1; i <= n; ++i) cout << ar[i];
  cout << '\n';
  if (false)
    cerr << "Time execute: " << (double)clock() / (double)CLOCKS_PER_SEC
         << " sec" << endl;
}
