#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int s[n + 1];
  for (int i = 0; i <= n; i++) s[i] = -1;
  int m;
  int ans = 1;
  cin >> m;
  while (m--) {
    int i, d;
    cin >> i >> d;
    if (s[i] == -1 || s[i] == d)
      s[i] = d;
    else
      ans = 0;
  }
  if (ans == 0)
    cout << -1;
  else {
    if (n == 1 || s[1] != 0) {
      if (s[1] == -1) s[1] = 1;
      for (int i = 1; i <= n; i++) {
        if (s[i] == -1) s[i] = 0;
        cout << s[i];
      }
    } else
      cout << -1;
  }
}
