#include <bits/stdc++.h>
using namespace std;
const bool DEBUG = true;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n, -1);
  bool flag = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (v[s] == -1)
      v[s] = c;
    else if (v[s] == c)
      continue;
    else
      flag = false;
  }
  if (v[0] == 0 && n != 1) flag = false;
  if (!flag) {
    cout << -1 << endl;
    return 0;
  }
  for (size_t i = 0; i < n; i++) {
    if (v[i] == -1) {
      if (i == 0)
        cout << 1;
      else
        cout << 0;
    } else {
      cout << v[i];
    }
  }
  cout << endl;
}
