#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<char> s(n + 1, '0');
  bool bl = true;
  for (int i = 1; i <= m; ++i) {
    int p, t;
    cin >> p >> t;
    if (s[p] != '0' && s[p] != t + '0') {
      bl = false;
    } else {
      s[p] = t + '0';
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (s[i] == '0') {
      bl = false;
      break;
    } else {
      break;
    }
  }
  if (bl)
    for (int i = 1; i <= n; ++i) cout << s[i];
  else
    cout << -1;
  return 0;
}
