#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n, -1);
  for (int i = 0; i < m; i++) {
    int S, c;
    cin >> S >> c;
    if (s[S - 1] == -1) {
      s[S - 1] = c;
    } else if (s[S - 1] != c) {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (s[0] <= 0 && n >= 2) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (s[i] == -1)
      cout << 0;
    else
      cout << s[i];
  }
  cout << endl;
}
