#include <bits/stdc++.h>
const int inf = (1 << 30);
const int mod = 1000000007;
using ll = long long;
using namespace std;
int no() {
  cout << -1 << endl;
  return 0;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> d(5, -1);
  if (m == 0) {
    if (n == 1) cout << 0 << endl;
    if (n == 2) cout << 10 << endl;
    if (n == 3) cout << 100 << endl;
    return 0;
  }
  while (m--) {
    int s, c;
    cin >> s >> c;
    if (d[s] == -1)
      d[s] = c;
    else if (d[s] != c)
      return no();
  }
  int erste = -1;
  for (int i = 1; i <= 3; ++i) {
    if (d[i] != -1) {
      erste = i;
      break;
    }
  }
  if (erste != 3 and d[4 - n] == 0) return no();
  for (int i = 1; i < 4 - n; ++i) {
    if (d[i] >= 1) return no();
  }
  for (int i = 4 - n; i <= 3; ++i) {
    if (d[i] != -1)
      cout << d[i];
    else if (i == 4 - n)
      cout << 1;
    else
      cout << 0;
  }
  cout << endl;
}
