#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n, -1);
  bool game = true;
  if (n == 1) {
    while (m--) {
      int x, y;
      cin >> x >> y;
      x--;
      if (v[x] != -1 && v[x] != y) {
        game = false;
      } else if (v[x] == -1) {
        v[x] = y;
      }
    }
    if (game) {
      cout << v[0];
    } else
      cout << -1 << endl;
  } else {
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      x--;
      if (v[x] != -1 && v[x] != y) {
        game = false;
      } else if (v[x] == -1) {
        if (x == 0 && y == 0) {
          game = false;
        }
        v[x] = y;
      }
    }
    if (game) {
      for (int i = 0; i < n; i++) {
        if (v[i] == -1 && i != 0)
          v[i] = 0;
        else if (v[i] == -1 && i == 0)
          v[i] = 1;
      }
      for (int i = 0; i < n; i++) cout << v[i];
      cout << endl;
    } else
      cout << -1 << endl;
  }
}
