#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(m, -1);
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (v[s] != -1 && v[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    v[s] = c;
  }
  int lmt = 1;
  for (int i = 0; i < (n); ++i) lmt *= 10;
  for (int i = 0; i < (lmt); ++i) {
    string s = to_string(i);
    bool ok = true;
    for (int j = 0; j < (n); ++j) {
      char c = v[j] + '0';
      if (v[j] == -1) continue;
      if (c != s[j]) ok = false;
    }
    if (ok) {
      cout << s << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
