#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;
int main() {
  int n;
  int m;
  cin >> n >> m;
  vector<int> ans(n, -1);
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (c == 0 && s == 0 && n != 1) {
      cout << -1 << endl;
      return 0;
    }
    if (ans[s] == -1 || ans[s] == c) {
      ans[s] = c;
      continue;
    }
    cout << -1 << endl;
    return 0;
  }
  for (int j = 0; j < n; ++j) {
    if (ans[j] == -1 && j != 0) ans[j] = 0;
    if (ans[j] == -1 && j == 0) ans[j] = 1;
  }
  int out = 0;
  for (int k = 0; k < n; ++k) {
    out += ans[k] * pow(10, n - (k + 1));
  }
  cout << out << endl;
}
