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