#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.exceptions(cin.failbit);
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<int> num(n, -1);
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (num[s] == -1) {
      num[s] = c;
    } else {
      if (s == 0 and num[s] == 0)
        num[s] = c;
      else {
        if (c != num[s]) {
          cout << -1 << '\n';
          return 0;
        }
      }
    }
  }
  if (num[0] == 0 and n > 1) {
    cout << -1 << '\n';
    return 0;
  }
  if (num[0] < 0) {
    num[0] = 1;
  }
  if (1 < n and num[1] < 0) num[1] = 0;
  if (2 < n and num[2] < 0) num[2] = 0;
  for (int i = 0; i < n; ++i) cout << num[i];
  cout << '\n';
  return 0;
}
