#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> d(n, -1);
  bool ok = true;
  for (int _ = 0; _ < (m); ++_) {
    int s, c;
    cin >> s >> c;
    s--;
    if (d[s] == -1 || d[s] == c)
      d[s] = c;
    else
      ok = false;
  }
  int aki = -1;
  for (int i = 0; i < (n); ++i) {
    if (d[i] == 0) {
      if (aki == -1)
        ok = false;
      else
        d[aki] = 1;
      break;
    } else if (d[i] > 0)
      break;
    else
      aki = i;
  }
  int ans = 0;
  if (ok) {
    for (int i = 0; i < (n); ++i) {
      ans *= 10;
      if (d[i] != -1) ans += d[i];
    }
  } else
    ans = -1;
  cout << ans << endl;
  return 0;
}
