#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  vector<int> s;
  vector<int> c;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int s_tmp;
    cin >> s_tmp;
    s.push_back(s_tmp);
    int c_tmp;
    cin >> c_tmp;
    c.push_back(c_tmp);
  }
  vector<bool> fixed;
  for (int i = 0; i < M; i++) {
    fixed.push_back(false);
  }
  vector<int> value;
  value.push_back(1);
  for (int i = 1; i < M; i++) {
    value.push_back(0);
  }
  int result = 0;
  for (int i = 0; i < M; i++) {
    if (fixed[s[i] - 1] == false) {
      if (s[i] == 1 && c[i] == 0) {
        result = -1;
        break;
      } else {
        value[s[i] - 1] = c[i];
        fixed[s[i] - 1] = true;
      }
    } else {
      if (c[i] != value[s[i] - 1]) {
        result = -1;
        break;
      }
    }
  }
  if (result != -1) {
    for (int i = 0; i < N; i++) {
      result += value[i] * pow(10.0, double(N - i - 1));
    }
  }
  cout << result << endl;
  return 0;
}
