#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  using pii = pair<int, int>;
  vector<pii> s(m);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> s[i].first >> s[i].second;
    s[i].first--;
    s[i].second--;
  }
  vector<vector<vector<int>>> common(n, vector<vector<int>>(n));
  vector<vector<int>> single(n);
  for (int i = 0; i < m; i++) {
    for (int j = s[i].first; j < s[i].second + 1; j++) {
      single[j].push_back(i);
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = s[i].first; j < s[i].second + 1; j++) {
      for (int k = j; k < s[i].second + 1; k++) {
        common[j][k].push_back(i);
        common[k][j].push_back(i);
      }
    }
  }
  int ans = 0;
  int a = 0, b = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      int curr = abs((v[i] - (int)single[i].size()) -
                     (v[j] - (int)common[i][j].size()));
      if (curr > ans) {
        ans = curr;
        a = i;
        b = j;
      }
      curr = abs((v[j] - (int)single[j].size()) -
                 (v[i] - (int)common[i][j].size()));
      if (curr > ans) {
        ans = curr;
        a = j;
        b = i;
      }
    }
  }
  cout << ans << '\n';
  cout << single[a].size() << '\n';
  for (int i = 0; i < single[a].size(); i++) {
    cout << single[a][i] + 1 << ' ';
  }
}
