#include <bits/stdc++.h>
using namespace std;
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(N, -1);
  for (int i = 0; i < (M); ++i) {
    int tmp_idx, tmp_num;
    cin >> tmp_idx >> tmp_num;
    tmp_idx--;
    if (s[tmp_idx] == -1) {
      s[tmp_idx] = tmp_num;
    } else {
      if (s[tmp_idx] != tmp_num) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  if (s[0] == 0 and N != 1) {
    cout << "-1" << endl;
    return 0;
  }
  if (s[0] == -1) s[0] == 1;
  int answer = 0;
  for (int i = 0; i < N; i++) {
    if (s[N - 1 - i] == -1) s[N - 1 - i] = 0;
    answer += s[N - 1 - i] * pow(10, i);
  }
  cout << answer << endl;
  return 0;
}
