#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a;
  cin >> n >> m;
  int p[5] = {10, 10, 10, 10, 10};
  int s[m];
  int c[m];
  int ans = 0;
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < m; i++) {
    if (s[i] > n) {
      cout << -1 << endl;
      return 0;
    }
    if (p[s[i] - 1] == 10) {
      p[s[i] - 1] = c[i];
    } else {
      if (p[s[i] - 1] != c[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (p[0] == 0) {
    cout << -1 << endl;
    return 0;
  } else {
    if (p[1] == 10 && p[2] == 10 && p[3] == 10 && p[4] == 10) {
      cout << p[0] << endl;
      return 0;
    } else {
      if (p[1] == 10) p[1] = 0;
      if (p[2] == 10 && p[3] == 10 && p[4] == 10) {
        cout << p[0] * 10 + p[1] << endl;
        return 0;
      } else {
        if (p[2] == 10) p[2] = 0;
        if (p[3] == 10 && p[4] == 10) {
          cout << p[0] * 100 + p[1] * 10 + p[2] << endl;
          return 0;
        } else {
          if (p[3] == 10) p[3] = 0;
          if (p[4] == 10) {
            cout << p[0] * 1000 + p[1] * 100 + p[2] * 10 + p[3] << endl;
            return 0;
          } else {
            cout << p[0] * 10000 + p[1] * 1000 + p[2] * 100 + p[3] * 10 + p[4]
                 << endl;
            return 0;
          }
        }
      }
    }
  }
  return 0;
}
