#include <bits/stdc++.h>
using namespace std;
bool kimari[3];
int suuji[3];
int main() {
  int n, m;
  cin >> n >> m;
  for (long long(i) = 0; (i) < (long long)(m); ++(i)) {
    int s, c;
    cin >> s >> c;
    s--;
    if (kimari[s]) {
      if (c != suuji[s]) {
        cout << "-1" << endl;
        return 0;
      }
    } else {
      kimari[s] = true;
      suuji[s] = c;
    }
  }
  for (long long(i) = 0; (i) < (long long)(n); ++(i)) {
    if (i == 0) {
      if (kimari[i]) {
        if (suuji[i] == 0) {
          cout << "-1" << endl;
          return 0;
        } else {
          cout << suuji[i];
        }
      } else {
        if (n == 1)
          cout << 0;
        else
          cout << 1;
      }
    } else {
      if (kimari[i]) {
        cout << suuji[i];
      } else {
        cout << 0;
      }
    }
  }
  return 0;
}
