#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int d[n + 10];
  for (int i = 1; i <= n; i++) {
    d[i] = 1000;
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    int s, c;
    cin >> s >> c;
    if (d[s] != 1000 && d[s] != c) {
      ans = -1;
      break;
    } else {
      d[s] = c;
    }
  }
  if (ans != -1) {
    for (int i = 1; i <= n; i++) {
      if (d[1] == 0) {
        ans = -1;
        break;
      }
      if (d[i] != 1000) ans += d[i] * pow(10, n - i);
    }
  }
  cout << ans << endl;
}
