#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<tuple<int, int>> a(m);
  int s, c;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    a.at(i) = make_tuple(s, c);
  }
  sort(a.begin(), a.end());
  bool b = true;
  for (int i = 0; i < m - 1; i++) {
    if (get<0>(a.at(i)) == get<0>(a.at(i + 1)) &&
        get<1>(a.at(i)) != get<1>(a.at(i + 1))) {
      b = false;
      break;
    }
  }
  if (get<0>(a.at(0)) == 1 && get<1>(a.at(0)) == 0) b = false;
  int ten = 1;
  if (b) {
    int ans = 0;
    if (get<0>(a.at(0)) == 1) {
      for (int i = n; i > 0; i--) {
        for (int j = 0; j < m; j++) {
          if (get<0>(a.at(j)) == i) {
            ans += get<1>(a.at(j)) * ten;
            break;
          }
        }
        ten *= 10;
      }
    } else {
      ans += pow(10, n);
      for (int i = n; i > 1; i--) {
        for (int j = 0; j < m; j++) {
          if (get<0>(a.at(j)) == i) {
            ans += get<1>(a.at(j)) * ten;
            break;
          }
        }
        ten *= 10;
      }
    }
    cout << ans << endl;
  } else
    cout << -1 << endl;
}
