#include <bits/stdc++.h>
using namespace std;
const int MAX = 5;
pair<int, int> s[5 + 1];
vector<char> nums(5);
void itoa(int a, int len) {
  int pos = 0;
  while (a > 0) {
    nums[pos++] = a % 10;
    a /= 10;
  }
  reverse(nums.begin(), nums.begin() + len);
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int j = 1; j <= m; ++j) {
    cin >> s[j].first >> s[j].second;
  }
  for (int i = 0; i < 1e3; ++i) {
    int len = 1;
    if (i >= 10) len++;
    if (i >= 100) len++;
    if (len != n) {
      continue;
    }
    itoa(i, len);
    int find = true;
    for (int j = 1; j <= m; ++j) {
      if (nums[s[j].first - 1] != s[j].second) {
        find = false;
      }
    }
    if (find) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
