#include <bits/stdc++.h>
using namespace std;
int n, m, p, c, nr[10];
bool viz[10];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> p >> c;
    if ((nr[p] != c && viz[p]) || (p == 1 && !c)) {
      cout << "-1";
      return 0;
    }
    viz[p] = true;
    nr[p] = c;
  }
  if (!nr[1]) nr[1] = 1;
  for (int i = 1; i <= n; ++i) cout << nr[i];
  return 0;
}
