#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  if (M == 0) {
    cout << (pow(10, N - 1)) << endl;
  } else {
    vector<int> s(M);
    vector<int> c(M);
    for (int i = 0; i < M; i++) {
      cin >> s.at(i) >> c.at(i);
    }
    int digit = 1;
    for (int i = 0; i < M; i++) {
      if (s.at(i) > digit) {
        digit = s.at(i);
      }
    }
    vector<int> val(digit);
    for (int i = 0; i < digit; i++) {
      val.at(i) = -1;
    }
    bool flag = false;
    for (int i = 0; i < M; i++) {
      if (val.at(digit - s.at(i)) != c.at(i) && val.at(digit - s.at(i)) != -1)
        flag = true;
      val.at(digit - s.at(i)) = c.at(i);
    }
    for (int i = 0; i < digit; i++) {
      if (val.at(i) == -1) val.at(i) = 0;
    }
    int ans = 0;
    if (flag) {
      ans = -1;
      cout << ans << endl;
    } else {
      for (int i = 0; i < digit; i++) {
        ans += pow(10, i) * val.at(i);
      }
      if (ans == 0 && N == 1) {
        cout << ans << endl;
      } else {
        if (ans >= pow(10, N - 1) && ans < pow(10, N)) {
          cout << ans << endl;
        } else {
          cout << -1 << endl;
        }
      }
    }
  }
}
