#include <bits/stdc++.h>
using namespace std;
int main() {
  int i = 0;
  int a[100] = {0};
  int c = 0;
  int e = 0;
  int b = 0;
  int n = 0;
  int m = 0;
  unordered_map<int, int> d;
  cin >> n;
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> c;
    cin >> b;
    if (c == 1 && b == 0 && n != 1) {
      cout << "-1";
      return 1;
    }
    if (c > n) {
      cout << "-1";
      return 1;
    }
    if (d[c]) {
      if (d[c] == b) {
        continue;
      }
      cout << "-1";
      return 1;
    } else {
      d.insert(pair<int, int>(c, b));
      d[c] = b;
    }
  }
  for (auto i = d.begin(); i != d.end(); i++) {
    a[i->first - 1] = i->second;
  }
  for (i = 0; i < n; i++) {
    e = 10 * e + a[i];
  }
  cout << e;
}
