#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> g(n, INT_MAX);
  bool r = true;
  for (int i = (0); i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    if (g[s - 1] != INT_MAX && g[s - 1] != c || s == 1 && c == 0) {
      cout << -1 << endl;
      r = false;
      break;
    }
    g[s - 1] = c;
  }
  if (r) {
    int x = 0;
    for (int i = (0); i < (n); ++i) {
      if (g[i] == INT_MAX) {
        if (i != n - 1) {
          g[i] = 0;
        } else {
          g[i] = 1;
        }
      }
      x += g[i] * pow(10, n - 1 - i);
    }
    cout << x << endl;
  }
}
