#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < (M); ++i) {
    cin >> s.at(i) >> c.at(i);
    --s.at(i);
  }
  string ans;
  bool exist = true;
  vector<int> num(N, -1);
  for (int i = 0; i < (M); ++i) {
    if (num.at(s.at(i)) != -1 && num.at(s.at(i)) != c.at(i)) {
      exist = false;
      break;
    } else {
      num.at(s.at(i)) = c.at(i);
    }
  }
  if (exist == true) {
    for (int i = 0; i < (N); ++i) {
      if (i == 0) {
        if (num.at(0) == 0) {
          exist = false;
          break;
        } else if (num.at(0) == -1) {
          ans.push_back('1');
        } else {
          ans.push_back('0' + num.at(0));
        }
      } else {
        if (num.at(i) == -1) {
          ans.push_back('0');
        } else {
          ans.push_back('0' + num.at(i));
        }
      }
    }
  }
  if (exist == false) ans = "-1";
  cout << ans << endl;
}
