#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  vector<int> d(n, -1);
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    if ((d[s - 1] != -1 && d[s - 1] != c) || (s == 1 && c == 0)) {
      cout << -1 << endl;
      return 0;
    }
    d[s - 1] = c;
  }
  if (d[0] == -1) d[0] = 1;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans = ans * 10 + (d[i] == -1 ? 0 : d[i]);
  }
  cout << ans << endl;
  return 0;
}
