#include <bits/stdc++.h>
using namespace std;
int fa(int x, int m) {
  int y = 1;
  for (int i = 0; i < m - x; i++) {
    y = y * 10;
  }
  return y;
}
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  int c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int ax = -11;
  for (int i = 0; i < m; i++) {
    ax = max(ax, s[i]);
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (i != j) {
        if (s[i] == s[j] && c[i] != c[j]) {
          cout << -1 << endl;
          return 0;
        }
        if (s[i] == s[j] && c[i] == c[j]) {
          s[i] = 0;
        }
      }
      if (ax == s[i] && c[i] == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (s[i] != 0) {
      ans = fa(s[i], ax) * c[i] + ans;
    }
  }
  cout << ans << endl;
}
