#include <bits/stdc++.h>
using namespace std;
void print_vector(vector<bool> firstTime) {
  for (int i = 0; i < firstTime.size(); i++) {
    cout << firstTime[i] << " ";
  }
  cout << endl;
}
void print_vector(vector<int> firstTime) {
  for (int i = 0; i < firstTime.size(); i++) {
    cout << firstTime[i] << " ";
  }
  cout << endl;
}
int main() {
  int N, M;
  cin >> N >> M;
  map<int, vector<int>> m;
  int pos, val;
  for (int i = 0; i < M; i++) {
    cin >> pos >> val;
    m[i] = {pos - 1, val};
  }
  vector<int> fillup(N, 0);
  vector<bool> first_time(N, false);
  for (auto it = m.begin(); it != m.end(); it++) {
    int pos = it->second[0];
    if (fillup[pos] != it->second[1] && first_time[pos]) {
      cout << -1 << endl;
      return 0;
    } else {
      fillup[pos] = it->second[1];
      first_time[pos] = true;
    }
  }
  string returningthis = "";
  for (int i = 0; i < N; i++) {
    if (fillup[i] == 0) {
      returningthis += '0';
    } else {
      returningthis += to_string(fillup[i]);
    }
  }
  int total_leading_zeros = 0;
  bool anything_else = false;
  for (int i = 0; i < returningthis.size(); i++) {
    if (returningthis[i] == '0' && anything_else == false) {
      total_leading_zeros++;
    } else {
      anything_else = true;
    }
  }
  if (total_leading_zeros >= 1) {
    cout << -1 << endl;
    return 0;
  }
  cout << returningthis << endl;
  return 0;
}
