#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M, ans = 0;
  vector<int> s, c, check;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int tmp;
    cin >> tmp;
    s.push_back(tmp);
    cin >> tmp;
    c.push_back(tmp);
    check.push_back(0);
  }
  for (int i = 0; i < M; i++) {
    for (int j = 1; j < M; j++) {
      if (s.at(i) == s.at(j)) {
        if (c.at(i) != c.at(j)) {
          ans = -1;
          break;
        }
      }
      if (c.at(i) == c.at(j)) {
        if (s.at(i) != s.at(j)) {
          ans = -1;
          break;
        }
      }
      if (s.at(i) == 1 && c.at(i) == 0) {
        ans = -1;
      }
    }
  }
  if (s.at(0) == 1 && c.at(0) == 0) {
    ans = -1;
  }
  if (ans != -1) {
    for (int i = 0; i < M; i++) {
      if (check.at(s.at(i) - 1) == 0) {
        ans += c.at(i) * pow(10.0, N - s.at(i));
        check.at(s.at(i) - 1) = 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
