#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(m, vector<int>(2));
  for (int i = 0; i < (int)(m); i++)
    for (int j = 0; j < (int)(2); j++) cin >> a.at(i).at(j);
  for (int i = 0; i < (int)(m); i++) {
    if (a.at(i).at(0) == 1 && a.at(i).at(1) == 0) {
      cout << -1 << endl;
      return 0;
    }
    for (int k = 0; k < (int)(m); k++)
      if (i != k && a.at(i).at(0) == a.at(k).at(0) &&
          a.at(i).at(1) != a.at(k).at(1)) {
        cout << -1 << endl;
        return 0;
      }
  }
  sort(a.begin(), a.end());
  string ans(n, '0');
  for (int i = 0; i < (int)(m); i++)
    ans.at(a.at(i).at(0) - 1) = '0' + a.at(i).at(1);
  cout << ans << endl;
}
