#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793238460;
const long long mod = 1e9 + 7;
void FAST() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int main() {
  FAST();
  int n, m, i;
  cin >> n >> m;
  int ans = 0;
  map<int, int> nos;
  while (m--) {
    int s, c;
    cin >> s >> c;
    if ((nos.find(s) != nos.end() && nos[s] != c) || (s == 1 && c == 0)) {
      cout << -1 << '\n';
      return 0;
    }
    nos[s] = c;
  }
  for (int i = 1; i < n + 1; ++i) {
    if (i == 1) {
      if (nos.find(i) == nos.end()) {
        if (n == 1)
          ans = 0;
        else
          ans = 1;
      } else
        ans = nos[1];
    } else {
      if (nos.find(i) == nos.end())
        ans = ans * 10 + 0;
      else
        ans = ans * 10 + nos[i];
    }
  }
  cout << ans << '\n';
  return 0;
}
