#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int ddx[4] = {1, 1, -1, -1};
const int ddy[4] = {1, -1, -1, 1};
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, -1);
  int s, c;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (a[s - 1] != -1 && a[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
    a[s - 1] = c;
  }
  if (a[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (a[0] == -1) a[0] = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] == -1)
      cout << 0;
    else
      cout << a[i];
  }
  cout << endl;
  return 0;
}
