#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  string s(n, 'a');
  int a, b;
  bool flag = true;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    --a;
    if (s[a] != 'a' && s[a] != (char)b + '0') {
      flag = false;
    }
    s[a] = (char)b + '0';
  }
  for (int i = 0; i < n; ++i) s[i] = (s[i] == 'a' ? '0' : s[i]);
  cout << (!flag || (n > 2 && s[n - 1] == '0') ? "-1" : s) << "\n";
  return 0;
}
