#include <bits/stdc++.h>
using namespace std;
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);
  bool ans = true;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s.at(i) == s.at(j)) {
        if (c.at(i) != c.at(j)) {
          ans = false;
          break;
        }
      }
    }
    if (ans == false) break;
  }
  for (int i = 0; i < m; ++i) {
    if (c.at(i) == 0) {
      if (s.at(i) == 1) {
        ans = false;
        break;
      }
    }
  }
  set<int> tmp;
  for (int x : s) {
    tmp.insert(x);
  }
  vector<int> num(n);
  for (int i = 0; i < m; ++i) {
    num.at(s.at(i) - 1) = c.at(i);
  }
  int ans_num = 0;
  for (int i = 0; i < n; ++i) {
    if (tmp.count(i + 1)) {
      ans_num += num.at(i) * pow(10, n - 1 - i);
    } else {
      if (i == n - 1) {
        ans_num += 1 * pow(10, n - 1 - i);
      }
    }
  }
  if (ans) {
    cout << ans_num << endl;
  } else {
    cout << -1 << endl;
  }
}
