#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pii> data(m);
  for (int i = 0; i < (int)(m); i++)
    cin >> data.at(i).first >> data.at(i).second;
  sort(data.begin(), data.end());
  vector<char> ans(n, '@');
  for (int i = 0; i < (int)(m); i++) {
    int s = data.at(i).first - 1;
    int c = data.at(i).second;
    if (ans.at(s) != '@' && ans.at(s) != ('0' + c)) {
      cout << -1 << endl;
      return 0;
    }
    ans.at(s) = '0' + c;
  }
  for (int i = 0; i < (int)(n); i++) {
    if (ans.at(i) == '@') ans.at(i) = '0';
  }
  if (n > 1) {
    if (ans.at(0) == '0') {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < (int)(n); i++) cout << ans.at(i);
  cout << endl;
}
