#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a, b;
  int s[n + 1];
  memset(s, -1, sizeof(s));
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    if (s[a] != -1 && b != s[a]) {
      cout << "-1" << endl;
      return 0;
    } else if (n > 1 && a == 1 && b == 0) {
      cout << "-1" << endl;
      return 0;
    } else
      s[a] = b;
  }
  for (int i = 1; i <= n; i++) {
    if (s[i] == -1) s[i] = 0;
  }
  for (int i = 1; i <= n; i++) cout << s[i];
  return 0;
}
