#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> *loc = new vector<int>[n + 1];
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    loc[x].push_back(y);
  }
  for (int i = 0; i <= n; i++) {
    sort(loc[i].begin(), loc[i].end());
  }
  string ans;
  for (int i = 1; i <= n; i++) {
    if (i == 1 && (loc[i].size() == 0 ||
                   (loc[i].size() == 1 && loc[i][0] == 0 && n > 1))) {
      cout << -1;
      return 0;
    }
    if (loc[i].size() != 0) {
      ans.push_back('0' + loc[i][0]);
    } else
      ans.push_back('0');
  }
  cout << ans;
}
