#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = 0, tmp1 = 0, tmp2 = 0;
  cin >> n >> m;
  vector<int> A(n);
  vector<pair<int, int>> SC;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    SC.push_back(make_pair(s, c));
  }
  sort(SC.begin(), SC.end());
  for (int i = 0; i < m; i++) {
    if (SC[i].first == 1 and SC[i].second == 0 and n > 1) {
      ans = -1;
      break;
    }
    if (tmp1 == SC[i].first) {
      if (tmp2 != SC[i].second) {
        ans = -1;
        break;
      } else
        continue;
    }
    tmp1 = SC[i].first;
    tmp2 = SC[i].second;
    ans += tmp2 * pow(10, n - tmp1);
  }
  if (ans != -1 and ans < pow(10, n - 1)) ans += pow(10, n - 1);
  cout << ans << endl;
}
