#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) a[i] = -1;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    if (a[x] == -1 || a[x] == y)
      a[x] = y;
    else
      return 0 * puts("-1");
  }
  if (n == 1) {
    if (a[1] >= 0)
      cout << a[1] << endl;
    else
      cout << 0 << endl;
  } else
    for (int i = 1; i <= n; i++) {
      if (a[1] == -1)
        cout << 1;
      else if (a[1] == 0)
        return 0 * puts("-1");
      else {
        if (a[i] == -1)
          cout << 0;
        else
          cout << a[i];
      }
    }
  return 0;
}
