#include <bits/stdc++.h>
using namespace std;
const int IINF = INT_MAX;
using ll = long long;
using P = pair<int, int>;
const double pai = 3.141592653589793238;
int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  int s[m];
  int c[m];
  for (int i = 0; i < m; i++) {
    int b;
    cin >> b >> c[i];
    b--;
    s[i] = b;
  }
  vector<int> box(n, -1);
  for (int i = 0; i < m; i++) {
    if (box[s[i]] >= 0 && box[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    box[s[i]] = c[i];
  }
  if (box[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int ten = 1;
    for (int j = 0; j < n - i - 1; j++) ten *= 10;
    if (box[i] == -1)
      continue;
    else if (box[0] == -1) {
      ans += 1 * ten;
    } else {
      ans += box[i] * ten;
    }
  }
  cout << ans << endl;
  return 0;
}
