#include <bits/stdc++.h>
using namespace std;
vector<int> a[1000];
int b[5];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= n; i++) a[i].clear();
  int s, c;
  for (int i = 1; i <= m; i++) {
    cin >> s >> c;
    a[s].push_back(c);
  }
  for (int i = 1; i <= n; i++) {
    if (a[i].size()) {
      for (auto v : a[i]) {
        if (v != a[i][0]) {
          cout << -1 << endl;
          return 0;
        }
      }
      sort(a[i].begin(), a[i].end());
      if (a[1][0] == 0) {
        cout << -1 << endl;
        return 0;
      }
      b[i] = a[i][0];
    } else {
      if (i == 1) {
        if (n == 1)
          b[1] = 0;
        else
          b[1] = 1;
      } else
        b[i] = 0;
    }
  }
  for (int i = 1; i <= n; i++) cout << b[i];
  return 0;
}
