#include <bits/stdc++.h>
using namespace std;
int pos[5];
int target[5];
int target_0indexed[5] = {-1, -1, -1, -1, -1};
bool is_used[5] = {false, false, false, false, false};
int pos_cnt[5];
int main() {
  int n, m;
  cin >> n >> m;
  int i;
  for (i = 0; i < m; ++i) {
    cin >> pos[i] >> target[i];
    --pos[i];
    if (is_used[pos[i]]) {
      if (target[i] == target_0indexed[pos[i]]) {
        cerr << "do nth" << endl;
        continue;
      }
    }
    is_used[pos[i]] = true;
    ++pos_cnt[pos[i]];
    target_0indexed[pos[i]] = target[i];
  }
  for (i = 0; i < m; ++i) {
    if (pos_cnt[i] > 1) {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (n > 1 && target_0indexed[0] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  string s = "";
  for (i = 0; i < n; ++i) {
    if (i > 0 && target_0indexed[i] == -1) target_0indexed[i] = 0;
    s += to_string(target_0indexed[i]);
  }
  cout << s << endl;
  return 0;
}
