#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  for (int i = 0; i < n; ++i) a[i] = 10;
  int s, c;
  for (int i = 0; i < m; ++i) {
    cin >> s >> c;
    if (a[s - 1] == 10)
      a[s - 1] = c;
    else {
      if (a[s - 1] != c) {
        cout << "-1" << '\n';
        return 0;
      }
    }
  }
  if (a[0] == 10 || a[0] == 0) {
    cout << "-1" << '\n';
  } else {
    string ss;
    for (int i = 0; i < n; ++i) {
      if (a[i] == 10) {
        ss.push_back('0');
      } else {
        ss += to_string(a[i]);
      }
    }
    cout << ss << '\n';
  }
  return 0;
}
